From b11994cc0136fc9f14949fdd3316ce032861f852 Mon Sep 17 00:00:00 2001
From: neil_a_wilson <neil_a_wilson@localhost>
Date: Wed, 06 Jun 2007 22:54:32 +0000
Subject: [PATCH] Update the server to provide better interoperability with the Penrose virtual directory. In particular, this commit exposes the LDAPClientConnection.sendLDAPMessage() method, and fixes a case in which short-circuiting out of the add operation processing in the pre-parse code with a success response could have resulted in a null pointer exception.
---
opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/core/DeleteOperationTestCase.java | 30 +++++++++++++++
opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/core/ModifyOperationTestCase.java | 35 +++++++++++++++++
opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/core/AddOperationTestCase.java | 37 ++++++++++++++++++
opendj-sdk/opends/src/server/org/opends/server/core/AddOperation.java | 4 +-
opendj-sdk/opends/src/server/org/opends/server/protocols/ldap/LDAPClientConnection.java | 10 ++--
5 files changed, 109 insertions(+), 7 deletions(-)
diff --git a/opendj-sdk/opends/src/server/org/opends/server/core/AddOperation.java b/opendj-sdk/opends/src/server/org/opends/server/core/AddOperation.java
index ea10a1a..96c516a 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/core/AddOperation.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/core/AddOperation.java
@@ -2230,7 +2230,7 @@
// Notify any change notification listeners that might be registered with
// the server.
- if (getResultCode() == ResultCode.SUCCESS)
+ if ((getResultCode() == ResultCode.SUCCESS) && (entry != null))
{
for (ChangeNotificationListener changeListener :
DirectoryServer.getChangeNotificationListeners())
@@ -2268,7 +2268,7 @@
// Notify any persistent searches that might be registered with the server.
- if (getResultCode() == ResultCode.SUCCESS)
+ if ((getResultCode() == ResultCode.SUCCESS) && (entry != null))
{
for (PersistentSearch persistentSearch :
DirectoryServer.getPersistentSearches())
diff --git a/opendj-sdk/opends/src/server/org/opends/server/protocols/ldap/LDAPClientConnection.java b/opendj-sdk/opends/src/server/org/opends/server/protocols/ldap/LDAPClientConnection.java
index 2a1ba16..802cb00 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/protocols/ldap/LDAPClientConnection.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/protocols/ldap/LDAPClientConnection.java
@@ -842,12 +842,12 @@
/**
* Sends the provided LDAP message to the client.
*
- * @param securityProvider The connection security provider to use to
- * handle any necessary security translation.
- * @param message The LDAP message to send to the client.
+ * @param secProvider The connection security provider to use to handle any
+ * necessary security translation.
+ * @param message The LDAP message to send to the client.
*/
- private void sendLDAPMessage(ConnectionSecurityProvider secProvider,
- LDAPMessage message)
+ public void sendLDAPMessage(ConnectionSecurityProvider secProvider,
+ LDAPMessage message)
{
ASN1Element messageElement = message.encode();
diff --git a/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/core/AddOperationTestCase.java b/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/core/AddOperationTestCase.java
index a942487..770ee7d 100644
--- a/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/core/AddOperationTestCase.java
+++ b/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/core/AddOperationTestCase.java
@@ -41,6 +41,7 @@
import org.opends.server.TestCaseUtils;
import org.opends.server.api.Backend;
import org.opends.server.plugins.DisconnectClientPlugin;
+import org.opends.server.plugins.ShortCircuitPlugin;
import org.opends.server.plugins.UpdatePreOpPlugin;
import org.opends.server.protocols.asn1.ASN1Element;
import org.opends.server.protocols.asn1.ASN1OctetString;
@@ -2487,5 +2488,41 @@
assertFalse(LDAPModify.mainModify(args, false, null, null) == 0);
}
+
+
+
+ /**
+ * Tests the behavior of the server when short-circuiting out of an add
+ * operation in the pre-parse phase with a success result code.
+ *
+ * @throws Exception If an unexpected problem occurs.
+ */
+ @Test()
+ public void testShortCircuitInPreParse()
+ throws Exception
+ {
+ TestCaseUtils.initializeTestBackend(false);
+
+ InternalClientConnection conn =
+ InternalClientConnection.getRootConnection();
+
+ List<Control> controls =
+ ShortCircuitPlugin.createShortCircuitControlList(0, "PreParse");
+
+ ArrayList<ByteString> ocValues = new ArrayList<ByteString>();
+ ocValues.add(new ASN1OctetString("top"));
+ ocValues.add(new ASN1OctetString("organization"));
+
+ ArrayList<RawAttribute> rawAttrs = new ArrayList<RawAttribute>();
+ rawAttrs.add(RawAttribute.create("objectClass", ocValues));
+ rawAttrs.add(RawAttribute.create("o", "test"));
+
+ AddOperation addOperation =
+ new AddOperation(conn, conn.nextOperationID(), conn.nextMessageID(),
+ controls, new ASN1OctetString("o=test"), rawAttrs);
+ addOperation.run();
+ assertEquals(addOperation.getResultCode(), ResultCode.SUCCESS);
+ assertFalse(DirectoryServer.entryExists(DN.decode("o=test")));
+ }
}
diff --git a/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/core/DeleteOperationTestCase.java b/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/core/DeleteOperationTestCase.java
index c18f578..71426a8 100644
--- a/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/core/DeleteOperationTestCase.java
+++ b/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/core/DeleteOperationTestCase.java
@@ -30,6 +30,7 @@
import java.net.Socket;
import java.util.ArrayList;
+import java.util.List;
import java.util.concurrent.locks.Lock;
import org.testng.annotations.BeforeClass;
@@ -39,6 +40,7 @@
import org.opends.server.TestCaseUtils;
import org.opends.server.api.Backend;
import org.opends.server.plugins.DisconnectClientPlugin;
+import org.opends.server.plugins.ShortCircuitPlugin;
import org.opends.server.protocols.asn1.ASN1Element;
import org.opends.server.protocols.asn1.ASN1OctetString;
import org.opends.server.protocols.asn1.ASN1Reader;
@@ -1129,5 +1131,33 @@
assertEquals(changeListener.getDeleteCount(), 0);
DirectoryServer.deregisterChangeNotificationListener(changeListener);
}
+
+
+
+ /**
+ * Tests the behavior of the server when short-circuiting out of a delete
+ * operation in the pre-parse phase with a success result code.
+ *
+ * @throws Exception If an unexpected problem occurs.
+ */
+ @Test()
+ public void testShortCircuitInPreParse()
+ throws Exception
+ {
+ TestCaseUtils.initializeTestBackend(true);
+
+ InternalClientConnection conn =
+ InternalClientConnection.getRootConnection();
+
+ List<Control> controls =
+ ShortCircuitPlugin.createShortCircuitControlList(0, "PreParse");
+
+ DeleteOperation deleteOperation =
+ new DeleteOperation(conn, conn.nextOperationID(), conn.nextMessageID(),
+ controls, new ASN1OctetString("o=test"));
+ deleteOperation.run();
+ assertEquals(deleteOperation.getResultCode(), ResultCode.SUCCESS);
+ assertTrue(DirectoryServer.entryExists(DN.decode("o=test")));
+ }
}
diff --git a/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/core/ModifyOperationTestCase.java b/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/core/ModifyOperationTestCase.java
index b97f9fa..61be52b 100644
--- a/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/core/ModifyOperationTestCase.java
+++ b/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/core/ModifyOperationTestCase.java
@@ -40,6 +40,7 @@
import org.opends.server.TestCaseUtils;
import org.opends.server.api.Backend;
import org.opends.server.plugins.DisconnectClientPlugin;
+import org.opends.server.plugins.ShortCircuitPlugin;
import org.opends.server.plugins.UpdatePreOpPlugin;
import org.opends.server.protocols.asn1.ASN1Element;
import org.opends.server.protocols.asn1.ASN1OctetString;
@@ -4502,5 +4503,39 @@
assertFalse(LDAPModify.mainModify(args, false, null, null) == 0);
}
+
+
+
+ /**
+ * Tests the behavior of the server when short-circuiting out of a modify
+ * operation in the pre-parse phase with a success result code.
+ *
+ * @throws Exception If an unexpected problem occurs.
+ */
+ @Test()
+ public void testShortCircuitInPreParse()
+ throws Exception
+ {
+ TestCaseUtils.initializeTestBackend(true);
+
+ InternalClientConnection conn =
+ InternalClientConnection.getRootConnection();
+
+ List<Control> controls =
+ ShortCircuitPlugin.createShortCircuitControlList(0, "PreParse");
+
+ ArrayList<RawModification> mods = new ArrayList<RawModification>();
+ mods.add(RawModification.create(ModificationType.REPLACE, "description",
+ "foo"));
+
+ ModifyOperation modifyOperation =
+ new ModifyOperation(conn, conn.nextOperationID(), conn.nextMessageID(),
+ controls, new ASN1OctetString("o=test"), mods);
+ modifyOperation.run();
+ assertEquals(modifyOperation.getResultCode(), ResultCode.SUCCESS);
+ assertTrue(DirectoryServer.entryExists(DN.decode("o=test")));
+ assertFalse(DirectoryServer.getEntry(DN.decode("o=test")).hasAttribute(
+ DirectoryServer.getAttributeType("description", true)));
+ }
}
--
Gitblit v1.10.0