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

Matthew Swift
12.12.2012 1056349c55bf501cd62b754dfa7dda091b0dabaf
Fix OPENDJ-322: Binary encoding option causing problems in replace operations

Thanks to Manuel Gaupp for the suggested patch.
2 files modified
60 ■■■■■ changed files
opends/src/server/org/opends/server/core/ModifyOperationBasis.java 1 ●●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/server/core/ModifyOperationTestCase.java 59 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/core/ModifyOperationBasis.java
@@ -254,6 +254,7 @@
               AttributeBuilder builder = new AttributeBuilder(attr);
               builder.setOption("binary");
               attr = builder.toAttribute();
               mod.setAttribute(attr);
             }
           }
           else
opends/tests/unit-tests-testng/src/server/org/opends/server/core/ModifyOperationTestCase.java
@@ -23,7 +23,7 @@
 *
 *
 *      Copyright 2006-2011 Sun Microsystems, Inc.
 *      Portions Copyright 2011 ForgeRock AS
 *      Portions Copyright 2011-2012 ForgeRock AS
 */
package org.opends.server.core;
@@ -4968,5 +4968,62 @@
    assertEquals(LDAPModify.mainModify(args, false, null, System.err), 0);
  }
  /**
   * Tests that the binary option is automatically added to modifications if it
   * is missing and required.
   *
   * @throws Exception
   *           If an unexpected problem occurs.
   */
  @Test(dataProvider = "baseDNs")
  public void testAddCertificateWithoutBinaryOption(String baseDN)
         throws Exception
  {
    TestCaseUtils.clearJEBackend(true,"userRoot",baseDN);
    TestCaseUtils.addEntry(
         "dn: uid=test.user," + baseDN,
         "objectClass: top",
         "objectClass: person",
         "objectClass: organizationalPerson",
         "objectClass: inetOrgPerson",
         "uid: test.user",
         "givenName: Test",
         "sn: User",
         "cn: Test User",
         "displayName: Test User",
         "userPassword: password",
         "mail: foo",
         "employeeNumber: 1");
    InternalClientConnection conn =
         InternalClientConnection.getRootConnection();
    ArrayList<ByteString> values = new ArrayList<ByteString>();
    values.add(ByteString.valueOf("2468"));
    LDAPAttribute attr = new LDAPAttribute("usercertificate", values);
    ArrayList<RawModification> mods = new ArrayList<RawModification>();
    mods.add(new LDAPModification(ModificationType.ADD, attr));
    ModifyOperation modifyOperation =
         conn.processModify(ByteString.valueOf("uid=test.user," + baseDN),
                            mods);
    assertEquals(modifyOperation.getResultCode(), ResultCode.SUCCESS);
    retrieveSuccessfulOperationElements(modifyOperation);
    Entry e = DirectoryServer.getEntry(DN.decode("uid=test.user," + baseDN));
    List<Attribute> attrList =
         e.getAttribute(DirectoryServer.getAttributeType("usercertificate",
                                                         true));
    assertNotNull(attrList);
    assertEquals(attrList.size(), 1);
    Attribute a = attrList.get(0);
    assertTrue(a.hasOption("binary"));
    assertEquals(a.size(), 1);
    assertEquals(a.iterator().next().getValue().toString(), "2468");
  }
}