Search in sources :

Example 11 with LDIFModifyDNChangeRecord

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

the class RenameAttributeTransformationTestCase method testTransformModifyDNChangeRecordExcludeDNs.

/**
 * Provides test coverage for the transformChangeRecord method for a modify DN
 * change record in which renames should not be applied in DNs.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testTransformModifyDNChangeRecordExcludeDNs() throws Exception {
    final Schema schema = Schema.getDefaultStandardSchema();
    final RenameAttributeTransformation t = new RenameAttributeTransformation(schema, "cn", "fullName", false);
    final LDIFChangeRecord r = t.transformChangeRecord(new LDIFModifyDNChangeRecord("cn=A,cn=B,dc=example,dc=com", "cn=C", true, "cn=D,dc=example,dc=com"));
    assertNotNull(r);
    assertEquals(r, new LDIFModifyDNChangeRecord("cn=A,cn=B,dc=example,dc=com", "cn=C", true, "cn=D,dc=example,dc=com"));
}
Also used : LDIFChangeRecord(com.unboundid.ldif.LDIFChangeRecord) Schema(com.unboundid.ldap.sdk.schema.Schema) LDIFModifyDNChangeRecord(com.unboundid.ldif.LDIFModifyDNChangeRecord) Test(org.testng.annotations.Test)

Example 12 with LDIFModifyDNChangeRecord

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

the class RedactAttributeTransformationTestCase method testTransformModDNChangeRecordProcessDNsFalsePreserveCountFalse.

/**
 * Provides test coverage for the transformChangeRecord method for a modify DN
 * record with both processDNs and preserveValueCount arguments set to false.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testTransformModDNChangeRecordProcessDNsFalsePreserveCountFalse() throws Exception {
    final Schema schema = Schema.getDefaultStandardSchema();
    final RedactAttributeTransformation t = new RedactAttributeTransformation(schema, false, false, "description", "displayName", "cn", "ou");
    LDIFChangeRecord r = t.transformChangeRecord(new LDIFModifyDNChangeRecord("cn=Test 1,ou=People,dc=example,dc=com", "cn=Test 2", true, null));
    assertNotNull(r);
    assertEquals(r, new LDIFModifyDNChangeRecord("cn=Test 1,ou=People,dc=example,dc=com", "cn=Test 2", true, null));
    r = t.transformChangeRecord(new LDIFModifyDNChangeRecord("cn=Test 1,ou=People,dc=example,dc=com", "cn=Test 2", true, "ou=Users,dc=example,dc=com"));
    assertNotNull(r);
    assertEquals(r, new LDIFModifyDNChangeRecord("cn=Test 1,ou=People,dc=example,dc=com", "cn=Test 2", true, "ou=Users,dc=example,dc=com"));
}
Also used : LDIFChangeRecord(com.unboundid.ldif.LDIFChangeRecord) Schema(com.unboundid.ldap.sdk.schema.Schema) LDIFModifyDNChangeRecord(com.unboundid.ldif.LDIFModifyDNChangeRecord) Test(org.testng.annotations.Test)

Example 13 with LDIFModifyDNChangeRecord

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

the class ModifyDNAuditLogMessageTestCase method testModifyAuditLogMessageWithMalformedModifications.

/**
 * Tests the behavior for a modify DN audit log message that cannot be
 * reverted because it has a malformed new RDN.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testModifyAuditLogMessageWithMalformedModifications() throws Exception {
    final ModifyDNAuditLogMessage m = new ModifyDNAuditLogMessage("# 27/Aug/2018:16:33:47.019 -0500; conn=31; op=1", "# ModifyDN attribute modifications (count=1)", "# malformed", "dn: uid=jdoe,ou=People,dc=example,dc=com", "changetype: moddn", "newrdn: uid=john.doe", "deleteoldrdn: 0");
    assertNotNull(m.getLogMessageLines());
    assertFalse(m.getLogMessageLines().isEmpty());
    assertNotNull(m.getCommentedHeaderLine());
    assertEquals(m.getCommentedHeaderLine(), "# 27/Aug/2018:16:33:47.019 -0500; conn=31; op=1");
    assertNotNull(m.getUncommentedHeaderLine());
    assertEquals(m.getUncommentedHeaderLine(), "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"));
    assertNull(m.getProductName());
    assertNull(m.getInstanceName());
    assertNull(m.getStartupID());
    assertNull(m.getThreadID());
    assertNull(m.getRequesterDN());
    assertNull(m.getRequesterIPAddress());
    assertNotNull(m.getConnectionID());
    assertEquals(m.getConnectionID().longValue(), 31L);
    assertNotNull(m.getOperationID());
    assertEquals(m.getOperationID().longValue(), 1L);
    assertNull(m.getTriggeredByConnectionID());
    assertNull(m.getTriggeredByOperationID());
    assertNull(m.getReplicationChangeID());
    assertNull(m.getAlternateAuthorizationDN());
    assertNull(m.getTransactionID());
    assertNull(m.getOrigin());
    assertNull(m.getUsingAdminSessionWorkerThread());
    assertNull(m.getRequestControlOIDs());
    assertNull(m.getOperationPurposeRequestControl());
    assertNull(m.getIntermediateClientRequestControl());
    assertNotNull(m.getDN());
    assertDNsEqual(m.getDN(), "uid=jdoe,ou=People,dc=example,dc=com");
    assertNotNull(m.getNewRDN());
    assertDNsEqual(m.getNewRDN(), "uid=john.doe");
    assertFalse(m.deleteOldRDN());
    assertNull(m.getNewSuperiorDN());
    assertNull(m.getAttributeModifications());
    assertNotNull(m.getChangeType());
    assertEquals(m.getChangeType(), ChangeType.MODIFY_DN);
    assertNotNull(m.getChangeRecord());
    assertTrue(m.getChangeRecord() instanceof LDIFModifyDNChangeRecord);
    assertFalse(m.isRevertible());
    try {
        m.getRevertChangeRecords();
        fail("Expected an exception when trying to revert a non-revertible " + "modify DN audit log message");
    } catch (final AuditLogException e) {
    // This was expected.
    }
    assertNotNull(m.toString());
    assertNotNull(m.toMultiLineString());
}
Also used : GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) LDIFModifyDNChangeRecord(com.unboundid.ldif.LDIFModifyDNChangeRecord) Test(org.testng.annotations.Test)

Example 14 with LDIFModifyDNChangeRecord

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

the class ModifyDNAuditLogMessageTestCase method testModifyAuditLogMessageWithMalformedNewRDN.

/**
 * Tests the behavior for a modify DN audit log message that cannot be
 * reverted because it has a malformed new RDN.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testModifyAuditLogMessageWithMalformedNewRDN() throws Exception {
    final ModifyDNAuditLogMessage m = new ModifyDNAuditLogMessage("# 27/Aug/2018:16:33:47.019 -0500; conn=31; op=1", "# ModifyDN attribute modifications (count=0)", "dn: uid=jdoe,ou=People,dc=example,dc=com", "changetype: moddn", "newrdn: malformed", "deleteoldrdn: 0");
    assertNotNull(m.getLogMessageLines());
    assertFalse(m.getLogMessageLines().isEmpty());
    assertNotNull(m.getCommentedHeaderLine());
    assertEquals(m.getCommentedHeaderLine(), "# 27/Aug/2018:16:33:47.019 -0500; conn=31; op=1");
    assertNotNull(m.getUncommentedHeaderLine());
    assertEquals(m.getUncommentedHeaderLine(), "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"));
    assertNull(m.getProductName());
    assertNull(m.getInstanceName());
    assertNull(m.getStartupID());
    assertNull(m.getThreadID());
    assertNull(m.getRequesterDN());
    assertNull(m.getRequesterIPAddress());
    assertNotNull(m.getConnectionID());
    assertEquals(m.getConnectionID().longValue(), 31L);
    assertNotNull(m.getOperationID());
    assertEquals(m.getOperationID().longValue(), 1L);
    assertNull(m.getTriggeredByConnectionID());
    assertNull(m.getTriggeredByOperationID());
    assertNull(m.getReplicationChangeID());
    assertNull(m.getAlternateAuthorizationDN());
    assertNull(m.getTransactionID());
    assertNull(m.getOrigin());
    assertNull(m.getUsingAdminSessionWorkerThread());
    assertNull(m.getRequestControlOIDs());
    assertNull(m.getOperationPurposeRequestControl());
    assertNull(m.getIntermediateClientRequestControl());
    assertNotNull(m.getDN());
    assertDNsEqual(m.getDN(), "uid=jdoe,ou=People,dc=example,dc=com");
    assertNotNull(m.getNewRDN());
    assertEquals(m.getNewRDN(), "malformed");
    assertFalse(m.deleteOldRDN());
    assertNull(m.getNewSuperiorDN());
    assertNotNull(m.getAttributeModifications());
    assertTrue(m.getAttributeModifications().isEmpty());
    assertNotNull(m.getChangeType());
    assertEquals(m.getChangeType(), ChangeType.MODIFY_DN);
    assertNotNull(m.getChangeRecord());
    assertTrue(m.getChangeRecord() instanceof LDIFModifyDNChangeRecord);
    assertFalse(m.isRevertible());
    try {
        m.getRevertChangeRecords();
        fail("Expected an exception when trying to revert a non-revertible " + "modify DN audit log message");
    } catch (final AuditLogException e) {
    // This was expected.
    }
    assertNotNull(m.toString());
    assertNotNull(m.toMultiLineString());
}
Also used : GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) LDIFModifyDNChangeRecord(com.unboundid.ldif.LDIFModifyDNChangeRecord) Test(org.testng.annotations.Test)

Example 15 with LDIFModifyDNChangeRecord

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

the class ModifyDNAuditLogMessageTestCase method testModifyAuditLogMessageMultipleNewRDNComponentsOneAlreadyThere.

/**
 * Tests the behavior for a revertible modify DN audit log message that has
 * multiple components in the new RDN, one of which is already present in the
 * entry and one that is not.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testModifyAuditLogMessageMultipleNewRDNComponentsOneAlreadyThere() throws Exception {
    final ModifyDNAuditLogMessage m = new ModifyDNAuditLogMessage("# 27/Aug/2018:22:42:11.929 -0500; conn=33; op=1; " + "productName=\"Directory Server\"; " + "instanceName=\"ReplicaOne\"; startupID=W4TELw==; threadID=13; " + "clientIP=127.0.0.1; " + "requesterDN=\"cn=Proxy User,cn=Root DNs,cn=config\"; " + "replicationChangeID=\"000001657E9FE1D473A700000007\"; " + "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=7\", " + "\"downstreamRequest\":{ " + "\"clientName\":\"Unidentified Directory Application\" } }", "# ModifyDN attribute modifications (count=1)", "# add: sn", "# sn: Smith", "dn: uid=jane.doe,ou=People,dc=example,dc=com", "changetype: moddn", "newrdn: givenName=Jane+sn=Smith", "deleteoldrdn: 0");
    assertNotNull(m.getLogMessageLines());
    assertFalse(m.getLogMessageLines().isEmpty());
    assertNotNull(m.getCommentedHeaderLine());
    assertTrue(m.getCommentedHeaderLine().startsWith("# 27/Aug/2018:22:42:11.929 -0500; conn=33; op=1; "));
    assertNotNull(m.getUncommentedHeaderLine());
    assertTrue(m.getUncommentedHeaderLine().startsWith("27/Aug/2018:22:42:11.929 -0500; conn=33; 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(), "W4TELw==");
    assertNotNull(m.getThreadID());
    assertEquals(m.getThreadID().longValue(), 13L);
    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(), 33L);
    assertNotNull(m.getOperationID());
    assertEquals(m.getOperationID().longValue(), 1L);
    assertNull(m.getTriggeredByConnectionID());
    assertNull(m.getTriggeredByOperationID());
    assertNotNull(m.getReplicationChangeID());
    assertEquals(m.getReplicationChangeID(), "000001657E9FE1D473A700000007");
    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(), "uid=jane.doe,ou=People,dc=example,dc=com");
    assertNotNull(m.getNewRDN());
    assertDNsEqual(m.getNewRDN(), "givenName=Jane+sn=Smith");
    assertFalse(m.deleteOldRDN());
    assertNull(m.getNewSuperiorDN());
    assertNotNull(m.getAttributeModifications());
    assertEquals(m.getAttributeModifications(), Collections.singletonList(new Modification(ModificationType.ADD, "sn", "Smith")));
    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(), "givenName=Jane+sn=Smith,ou=People,dc=example,dc=com");
    assertDNsEqual(revertModifyDNChangeRecord.getNewRDN(), "uid=jane.doe");
    assertFalse(revertModifyDNChangeRecord.deleteOldRDN());
    assertNull(revertModifyDNChangeRecord.getNewSuperiorDN());
    final LDIFModifyChangeRecord revertModifyChangeRecord = (LDIFModifyChangeRecord) revertChangeRecords.get(1);
    assertDNsEqual(revertModifyChangeRecord.getDN(), "uid=jane.doe,ou=People,dc=example,dc=com");
    assertEquals(revertModifyChangeRecord.getModifications(), new Modification[] { new Modification(ModificationType.DELETE, "sn", "Smith") });
    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)

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