mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

neil_a_wilson
07.54.2007 54e8ec5df0926adf4fb734ef2780a9a62b6161b7
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.

OpenDS Issue Number: 1729
5 files modified
116 ■■■■■ changed files
opends/src/server/org/opends/server/core/AddOperation.java 4 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/protocols/ldap/LDAPClientConnection.java 10 ●●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/server/core/AddOperationTestCase.java 37 ●●●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/server/core/DeleteOperationTestCase.java 30 ●●●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/server/core/ModifyOperationTestCase.java 35 ●●●●● patch | view | raw | blame | history
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())
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();
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")));
  }
}
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")));
  }
}
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)));
  }
}