Search in sources :

Example 16 with LDIFModifyDNChangeRecord

use of com.unboundid.ldif.LDIFModifyDNChangeRecord in project ldapsdk by pingidentity.

the class ModifyDNAuditLogMessageTestCase method testModifyAuditLogMessageWithAdditionalMods.

/**
 * Tests the behavior for a revertible modify DN audit log message that has
 * additional modifications not related to the RDN change.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testModifyAuditLogMessageWithAdditionalMods() throws Exception {
    final ModifyDNAuditLogMessage m = new ModifyDNAuditLogMessage("# 27/Aug/2018:16:33:47.019 -0500; conn=31; op=1; " + "productName=\"Directory Server\"; " + "instanceName=\"ReplicaOne\"; startupID=W4Rt1g==; threadID=8; " + "clientIP=127.0.0.1; " + "requesterDN=\"cn=Proxy User,cn=Root DNs,cn=config\"; " + "replicationChangeID=\"000001657D4E9677214B00000005\"; " + "authzDN=\"cn=Directory Manager,cn=Root DNs,cn=config\"; " + "requestControlOIDs=\"1.3.6.1.4.1.30221.2.5.2\"; " + "intermediateClientRequestControl={ " + "\"clientIdentity\":\"dn:cn=Directory Manager,cn=Root " + "DNs,cn=config\", \"downstreamClientAddress\":\"127.0.0.1\", " + "\"downstreamClientSecure\":false, " + "\"clientName\":\"PingDirectory\", " + "\"clientSessionID\":\"conn=8\", \"clientRequestID\":\"op=5\", " + "\"downstreamRequest\":{ " + "\"clientName\":\"Unidentified Directory Application\" } }", "# ModifyDN attribute modifications (count=6)", "# delete: givenName", "# givenName: John", "# givenName: Johnny", "# -", "# delete: sn", "# sn: Doe", "# sn: A Female Deer", "# -", "# add: uid", "# uid: jdoe", "# uid: john.doe", "# -", "# delete: displayName", "# displayName: foo", "# -", "# add: description", "# description: bar", "# -", "# increment: intAttr", "# intAttr: 1", "dn: givenName=John+sn=Doe,ou=People,dc=example,dc=com", "changetype: moddn", "newrdn: uid=jdoe", "deleteoldrdn: 1");
    assertNotNull(m.getLogMessageLines());
    assertFalse(m.getLogMessageLines().isEmpty());
    assertNotNull(m.getCommentedHeaderLine());
    assertTrue(m.getCommentedHeaderLine().startsWith("# 27/Aug/2018:16:33:47.019 -0500; conn=31; op=1; "));
    assertNotNull(m.getUncommentedHeaderLine());
    assertTrue(m.getUncommentedHeaderLine().startsWith("27/Aug/2018:16:33:47.019 -0500; conn=31; op=1; "));
    assertNotNull(m.getTimestamp());
    final Calendar calendar = new GregorianCalendar();
    calendar.setTime(m.getTimestamp());
    assertEquals(calendar.get(Calendar.YEAR), 2018);
    assertEquals(calendar.get(Calendar.MONTH), Calendar.AUGUST);
    assertNotNull(m.getHeaderNamedValues());
    assertFalse(m.getHeaderNamedValues().isEmpty());
    assertTrue(m.getHeaderNamedValues().containsKey("conn"));
    assertNotNull(m.getProductName());
    assertEquals(m.getProductName(), "Directory Server");
    assertNotNull(m.getInstanceName());
    assertEquals(m.getInstanceName(), "ReplicaOne");
    assertNotNull(m.getStartupID());
    assertEquals(m.getStartupID(), "W4Rt1g==");
    assertNotNull(m.getThreadID());
    assertEquals(m.getThreadID().longValue(), 8L);
    assertNotNull(m.getRequesterDN());
    assertDNsEqual(m.getRequesterDN(), "cn=Proxy User,cn=Root DNs,cn=config");
    assertNotNull(m.getRequesterIPAddress());
    assertEquals(m.getRequesterIPAddress(), "127.0.0.1");
    assertNotNull(m.getConnectionID());
    assertEquals(m.getConnectionID().longValue(), 31L);
    assertNotNull(m.getOperationID());
    assertEquals(m.getOperationID().longValue(), 1L);
    assertNull(m.getTriggeredByConnectionID());
    assertNull(m.getTriggeredByOperationID());
    assertNotNull(m.getReplicationChangeID());
    assertEquals(m.getReplicationChangeID(), "000001657D4E9677214B00000005");
    assertNotNull(m.getAlternateAuthorizationDN());
    assertDNsEqual(m.getAlternateAuthorizationDN(), "cn=Directory Manager,cn=Root DNs,cn=config");
    assertNull(m.getTransactionID());
    assertNull(m.getOrigin());
    assertNull(m.getUsingAdminSessionWorkerThread());
    assertNotNull(m.getRequestControlOIDs());
    assertEquals(m.getRequestControlOIDs(), Collections.singletonList("1.3.6.1.4.1.30221.2.5.2"));
    assertNull(m.getOperationPurposeRequestControl());
    assertNotNull(m.getIntermediateClientRequestControl());
    assertNotNull(m.getDN());
    assertDNsEqual(m.getDN(), "givenName=John+sn=Doe,ou=People,dc=example,dc=com");
    assertNotNull(m.getNewRDN());
    assertDNsEqual(m.getNewRDN(), "uid=jdoe");
    assertTrue(m.deleteOldRDN());
    assertNull(m.getNewSuperiorDN());
    assertNotNull(m.getAttributeModifications());
    assertEquals(m.getAttributeModifications(), Arrays.asList(new Modification(ModificationType.DELETE, "givenName", "John", "Johnny"), new Modification(ModificationType.DELETE, "sn", "Doe", "A Female Deer"), new Modification(ModificationType.ADD, "uid", "jdoe", "john.doe"), new Modification(ModificationType.DELETE, "displayName", "foo"), new Modification(ModificationType.ADD, "description", "bar"), new Modification(ModificationType.INCREMENT, "intAttr", "1")));
    assertNotNull(m.getChangeType());
    assertEquals(m.getChangeType(), ChangeType.MODIFY_DN);
    assertNotNull(m.getChangeRecord());
    assertTrue(m.getChangeRecord() instanceof LDIFModifyDNChangeRecord);
    assertTrue(m.isRevertible());
    final List<LDIFChangeRecord> revertChangeRecords = m.getRevertChangeRecords();
    assertNotNull(revertChangeRecords);
    assertFalse(revertChangeRecords.isEmpty());
    assertEquals(revertChangeRecords.size(), 2);
    assertTrue(revertChangeRecords.get(0) instanceof LDIFModifyDNChangeRecord);
    assertTrue(revertChangeRecords.get(1) instanceof LDIFModifyChangeRecord);
    final LDIFModifyDNChangeRecord revertModifyDNChangeRecord = (LDIFModifyDNChangeRecord) revertChangeRecords.get(0);
    assertDNsEqual(revertModifyDNChangeRecord.getDN(), "uid=jdoe,ou=People,dc=example,dc=com");
    assertDNsEqual(revertModifyDNChangeRecord.getNewRDN(), "givenName=John+sn=Doe");
    assertTrue(revertModifyDNChangeRecord.deleteOldRDN());
    assertNull(revertModifyDNChangeRecord.getNewSuperiorDN());
    final LDIFModifyChangeRecord revertModifyChangeRecord = (LDIFModifyChangeRecord) revertChangeRecords.get(1);
    assertDNsEqual(revertModifyChangeRecord.getDN(), "givenName=John+sn=Doe,ou=People,dc=example,dc=com");
    assertEquals(revertModifyChangeRecord.getModifications(), new Modification[] { new Modification(ModificationType.INCREMENT, "intAttr", "-1"), new Modification(ModificationType.DELETE, "description", "bar"), new Modification(ModificationType.ADD, "displayName", "foo"), new Modification(ModificationType.DELETE, "uid", "john.doe"), new Modification(ModificationType.ADD, "sn", "A Female Deer"), new Modification(ModificationType.ADD, "givenName", "Johnny") });
    assertNotNull(m.toString());
    assertNotNull(m.toMultiLineString());
}
Also used : Modification(com.unboundid.ldap.sdk.Modification) LDIFChangeRecord(com.unboundid.ldif.LDIFChangeRecord) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) LDIFModifyChangeRecord(com.unboundid.ldif.LDIFModifyChangeRecord) LDIFModifyDNChangeRecord(com.unboundid.ldif.LDIFModifyDNChangeRecord) Test(org.testng.annotations.Test)

Example 17 with LDIFModifyDNChangeRecord

use of com.unboundid.ldif.LDIFModifyDNChangeRecord in project ldapsdk by pingidentity.

the class UnboundIDChangeLogEntryTestCase method testBasicModifyDNChangeLogEntry.

/**
 * Provides coverage for cases in which an UnboundID changelog entry is
 * created for a modify DN operation without any UnboundID-specific content.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testBasicModifyDNChangeLogEntry() throws Exception {
    final ChangeLogEntry e = ChangeLogEntry.constructChangeLogEntry(4L, new LDIFModifyDNChangeRecord("uid=test.user,ou=People,dc=example,dc=com", "cn=Test User", false, null));
    assertNotNull(e);
    final UnboundIDChangeLogEntry ue = new UnboundIDChangeLogEntry(e);
    assertNotNull(ue);
    assertEquals(ue.getChangeNumber(), 4L);
    assertNotNull(ue.getTargetDN());
    assertEquals(new DN(ue.getTargetDN()), new DN("uid=test.user,ou=People,dc=example,dc=com"));
    assertNotNull(ue.getChangeType());
    assertEquals(ue.getChangeType(), ChangeType.MODIFY_DN);
    assertNull(ue.getAddAttributes());
    assertNull(ue.getDeletedEntryAttributes());
    assertNull(ue.getModifications());
    assertNotNull(ue.getNewRDN());
    assertEquals(new RDN(ue.getNewRDN()), new RDN("cn=Test User"));
    assertFalse(ue.deleteOldRDN());
    assertNull(ue.getNewSuperior());
    assertNull(ue.getSoftDeleteToDN());
    assertNull(ue.getUndeleteFromDN());
    assertNull(ue.getChangeToSoftDeletedEntry());
    assertNotNull(ue.getNewDN());
    assertEquals(new DN(ue.getNewDN()), new DN("cn=Test User,ou=People,dc=example,dc=com"));
    assertNotNull(ue.getUpdatedAttributesBeforeChange());
    assertTrue(ue.getUpdatedAttributesBeforeChange().isEmpty());
    assertNotNull(ue.getUpdatedAttributesAfterChange());
    assertTrue(ue.getUpdatedAttributesAfterChange().isEmpty());
    assertNotNull(ue.getAttributesThatExceededMaxValuesCount());
    assertTrue(ue.getAttributesThatExceededMaxValuesCount().isEmpty());
    assertNotNull(ue.getKeyEntryAttributes());
    assertTrue(ue.getKeyEntryAttributes().isEmpty());
    assertEquals(ue.getNumExcludedUserAttributes(), -1);
    assertEquals(ue.getNumExcludedOperationalAttributes(), -1);
    assertNotNull(ue.getExcludedUserAttributeNames());
    assertTrue(ue.getExcludedUserAttributeNames().isEmpty());
    assertNotNull(ue.getExcludedOperationalAttributeNames());
    assertTrue(ue.getExcludedOperationalAttributeNames().isEmpty());
    assertNull(ue.getAttributeBeforeChange("uid"));
    assertNull(ue.getAttributeBeforeChange("cn"));
    assertNull(ue.getAttributeBeforeChange("description"));
    assertNull(ue.getAttributeAfterChange("uid"));
    assertNull(ue.getAttributeAfterChange("cn"));
    assertNull(ue.getAttributeAfterChange("description"));
    assertNotNull(ue.constructPartialEntryBeforeChange());
    assertEquals(ue.constructPartialEntryBeforeChange(), new Entry("uid=test.user,ou=People,dc=example,dc=com"));
    assertNotNull(ue.constructPartialEntryAfterChange());
    assertEquals(ue.constructPartialEntryAfterChange(), new Entry("cn=Test User,ou=People,dc=example,dc=com"));
    assertNull(ue.getTargetUniqueID());
    assertNull(ue.getLocalCSN());
    assertNull(ue.getChangeTime());
    assertNotNull(ue.getTargetAttributeNames());
    assertTrue(ue.getTargetAttributeNames().isEmpty());
    assertNotNull(ue.getNotificationDestinationEntryUUIDs());
    assertTrue(ue.getNotificationDestinationEntryUUIDs().isEmpty());
    assertNotNull(ue.getNotificationProperties());
    assertTrue(ue.getNotificationProperties().isEmpty());
}
Also used : Entry(com.unboundid.ldap.sdk.Entry) ChangeLogEntry(com.unboundid.ldap.sdk.ChangeLogEntry) ChangeLogEntry(com.unboundid.ldap.sdk.ChangeLogEntry) RDN(com.unboundid.ldap.sdk.RDN) DN(com.unboundid.ldap.sdk.DN) RDN(com.unboundid.ldap.sdk.RDN) LDIFModifyDNChangeRecord(com.unboundid.ldif.LDIFModifyDNChangeRecord) Test(org.testng.annotations.Test)

Example 18 with LDIFModifyDNChangeRecord

use of com.unboundid.ldif.LDIFModifyDNChangeRecord in project ldapsdk by pingidentity.

the class ParallelUpdateTestCase method testRejectedModifyDN.

/**
 * Tests with a rejected modify DN operation because the entry does not exist.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testRejectedModifyDN() throws Exception {
    final File ldifFile = createTempFile("dn: ou=People,dc=example,dc=com", "changetype: moddn", "newrdn: ou=Users", "deleteoldrdn: 1");
    final File rejectFile = createTempFile();
    final InMemoryDirectoryServer ds = getTestDS(false, false);
    assertEquals(ParallelUpdate.main(NO_OUTPUT, NO_OUTPUT, "--hostname", "localhost", "--port", String.valueOf(ds.getListenPort()), "--ldifFile", ldifFile.getAbsolutePath(), "--rejectFile", rejectFile.getAbsolutePath(), "--useFirstRejectResultCodeAsExitCode"), ResultCode.NO_SUCH_OBJECT);
    try (LDIFReader reader = new LDIFReader(rejectFile)) {
        final LDIFChangeRecord changeRecord = reader.readChangeRecord(true);
        assertNotNull(changeRecord);
        assertTrue(changeRecord instanceof LDIFModifyDNChangeRecord);
        assertDNsEqual(changeRecord.getDN(), "ou=People,dc=example,dc=com");
        assertNull(reader.readChangeRecord());
    }
}
Also used : LDIFChangeRecord(com.unboundid.ldif.LDIFChangeRecord) InMemoryDirectoryServer(com.unboundid.ldap.listener.InMemoryDirectoryServer) LDIFReader(com.unboundid.ldif.LDIFReader) File(java.io.File) LDIFModifyDNChangeRecord(com.unboundid.ldif.LDIFModifyDNChangeRecord) Test(org.testng.annotations.Test)

Example 19 with LDIFModifyDNChangeRecord

use of com.unboundid.ldif.LDIFModifyDNChangeRecord in project ldapsdk by pingidentity.

the class ChangeLogEntryTestCase method testConstructModifyDNChangeLogEntryWithNewSuperior.

/**
 * Tests the ability to construct a changelog entry for a modify DN operation
 * with a new superior.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testConstructModifyDNChangeLogEntryWithNewSuperior() throws Exception {
    final ChangeLogEntry e = ChangeLogEntry.constructChangeLogEntry(3L, new LDIFModifyDNChangeRecord("ou=People,dc=example,dc=com", "ou=Users", true, "o=example.com"));
    assertNotNull(e);
    assertEquals(e.getChangeNumber(), 3L);
    assertEquals(new DN(e.getTargetDN()), new DN("ou=People,dc=example,dc=com"));
    assertEquals(e.getChangeType(), ChangeType.MODIFY_DN);
    assertNull(e.getAddAttributes());
    assertNull(e.getDeletedEntryAttributes());
    assertNull(e.getModifications());
    assertEquals(new RDN(e.getNewRDN()), new RDN("ou=Users"));
    assertTrue(e.deleteOldRDN());
    assertEquals(new DN(e.getNewSuperior()), new DN("o=example.com"));
    assertTrue(e.toLDIFChangeRecord() instanceof LDIFModifyDNChangeRecord);
}
Also used : LDIFModifyDNChangeRecord(com.unboundid.ldif.LDIFModifyDNChangeRecord) Test(org.testng.annotations.Test)

Example 20 with LDIFModifyDNChangeRecord

use of com.unboundid.ldif.LDIFModifyDNChangeRecord in project ldapsdk by pingidentity.

the class ChangeLogEntryTestCase method testGetNewDN.

/**
 * Provides test coverage for the {@code getNewDN} method with various types
 * of changes.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testGetNewDN() throws Exception {
    // For add and modify operations, the new DN should always be the same as
    // the target DN.
    ChangeLogEntry e = ChangeLogEntry.constructChangeLogEntry(1L, new LDIFAddChangeRecord(new Entry("dn: dc=example,dc=com", "objectClass: top", "objectClass: domain", "dc: example")));
    assertEquals(new DN(e.getNewDN()), new DN("dc=example,dc=com"));
    e = ChangeLogEntry.constructChangeLogEntry(2L, new LDIFModifyChangeRecord("dc=example,dc=com", new Modification(ModificationType.REPLACE, "description", "foo")));
    assertEquals(new DN(e.getNewDN()), new DN("dc=example,dc=com"));
    // For delete operations, the new DN should always be null.
    e = ChangeLogEntry.constructChangeLogEntry(3L, new LDIFDeleteChangeRecord("dc=example,dc=com"));
    assertNull(e.getNewDN());
    // For modify DN operations, then the new DN will depend on whether or not
    // there's a new superior DN.
    e = ChangeLogEntry.constructChangeLogEntry(4L, new LDIFModifyDNChangeRecord("ou=People,dc=example,dc=com", "ou=Users", true, null));
    assertEquals(new DN(e.getNewDN()), new DN("ou=Users,dc=example,dc=com"));
    e = ChangeLogEntry.constructChangeLogEntry(5L, new LDIFModifyDNChangeRecord("ou=People,dc=example,dc=com", "ou=Users", true, "o=example.com"));
    assertEquals(new DN(e.getNewDN()), new DN("ou=Users,o=example.com"));
    e = ChangeLogEntry.constructChangeLogEntry(6L, new LDIFModifyDNChangeRecord("o=example.com", "o=example.net", true, null));
    assertEquals(new DN(e.getNewDN()), new DN("o=example.net"));
}
Also used : LDIFAddChangeRecord(com.unboundid.ldif.LDIFAddChangeRecord) LDIFModifyChangeRecord(com.unboundid.ldif.LDIFModifyChangeRecord) LDIFDeleteChangeRecord(com.unboundid.ldif.LDIFDeleteChangeRecord) LDIFModifyDNChangeRecord(com.unboundid.ldif.LDIFModifyDNChangeRecord) Test(org.testng.annotations.Test)

Aggregations

LDIFModifyDNChangeRecord (com.unboundid.ldif.LDIFModifyDNChangeRecord)45 Test (org.testng.annotations.Test)35 LDIFModifyChangeRecord (com.unboundid.ldif.LDIFModifyChangeRecord)20 LDIFChangeRecord (com.unboundid.ldif.LDIFChangeRecord)19 LDIFAddChangeRecord (com.unboundid.ldif.LDIFAddChangeRecord)17 LDIFDeleteChangeRecord (com.unboundid.ldif.LDIFDeleteChangeRecord)17 Calendar (java.util.Calendar)13 GregorianCalendar (java.util.GregorianCalendar)13 Entry (com.unboundid.ldap.sdk.Entry)10 Modification (com.unboundid.ldap.sdk.Modification)8 ModifyRequest (com.unboundid.ldap.sdk.ModifyRequest)8 DN (com.unboundid.ldap.sdk.DN)7 LDAPException (com.unboundid.ldap.sdk.LDAPException)5 Schema (com.unboundid.ldap.sdk.schema.Schema)5 LDIFReader (com.unboundid.ldif.LDIFReader)4 Nullable (com.unboundid.util.Nullable)4 File (java.io.File)4 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)3 Attribute (com.unboundid.ldap.sdk.Attribute)3 RDN (com.unboundid.ldap.sdk.RDN)3