Search in sources :

Example 16 with TestLogHandler

use of com.unboundid.util.TestLogHandler in project ldapsdk by pingidentity.

the class JSONLDAPConnectionLoggerTestCase method testSASLBindLogging.

/**
 * Tests the behavior when logging SASL bind operations.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testSASLBindLogging() throws Exception {
    // Get the in-memory directory server instance.
    final InMemoryDirectoryServer ds = getTestDS();
    // Create a logger to use for the test.
    final TestLogHandler logHandler = new TestLogHandler();
    final JSONLDAPConnectionLoggerProperties properties = new JSONLDAPConnectionLoggerProperties();
    final JSONLDAPConnectionLogger logger = new JSONLDAPConnectionLogger(logHandler, properties);
    final LDAPConnectionOptions options = new LDAPConnectionOptions();
    options.setConnectionLogger(logger);
    // Establish a connection and send a SASL bind request on it.
    try (LDAPConnection connection = new LDAPConnection(options, "localhost", ds.getListenPort())) {
        connection.bind(new PLAINBindRequest("dn:cn=Directory Manager", "password"));
    }
    // Make sure that there were five log messages:
    // - Connect
    // - Bind request
    // - Bind result
    // - Unbind
    // - Disconnect
    assertEquals(logHandler.getMessageCount(), 5, logHandler.getMessagesString());
    final List<JSONObject> logMessages = parseLogMessages(logHandler);
    assertMessageIs(logMessages.get(0), "connect", null);
    assertMessageIs(logMessages.get(1), "request", OperationType.BIND);
    assertMessageIs(logMessages.get(2), "result", OperationType.BIND);
    assertMessageIs(logMessages.get(3), "request", OperationType.UNBIND);
    assertMessageIs(logMessages.get(4), "disconnect", null);
}
Also used : TestLogHandler(com.unboundid.util.TestLogHandler) JSONObject(com.unboundid.util.json.JSONObject) InMemoryDirectoryServer(com.unboundid.ldap.listener.InMemoryDirectoryServer) Test(org.testng.annotations.Test)

Example 17 with TestLogHandler

use of com.unboundid.util.TestLogHandler in project ldapsdk by pingidentity.

the class JSONLDAPConnectionLoggerTestCase method testAddWithRedactionNeededInDNAndAttributes.

/**
 * Provides coverage for the case in which an add request includes a DN and
 * attribute values that require redaction.
 *
 * Tests the behavior when logging search operations.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testAddWithRedactionNeededInDNAndAttributes() throws Exception {
    // Get the in-memory directory server instance.
    final InMemoryDirectoryServer ds = getTestDS(false, false);
    // Create a logger to use for the test.
    final TestLogHandler logHandler = new TestLogHandler();
    final JSONLDAPConnectionLoggerProperties properties = new JSONLDAPConnectionLoggerProperties();
    properties.setAttributesToRedact("userPassword", "authPassword", "ssn");
    properties.setIncludeAddAttributeNames(true);
    properties.setIncludeAddAttributeValues(true);
    final JSONLDAPConnectionLogger logger = new JSONLDAPConnectionLogger(logHandler, properties);
    final LDAPConnectionOptions options = new LDAPConnectionOptions();
    options.setConnectionLogger(logger);
    // Generate a log message.
    try (LDAPConnection connection = ds.getConnection()) {
        final AddRequest addRequest = new AddRequest("dn: userPassword=password,ou=People,dc=example,dc=com", "objectClass: top", "objectClass: person", "objectClass: organizationalPerson", "objectClass: inetOrgPerson", "uid: test.user", "givenName: Test", "sn: user", "cn: Test User", "userPassword: password");
        logger.logAddRequest(connection, 1, addRequest);
    }
    // Make sure that we can decode the message.
    assertEquals(logHandler.getMessageCount(), 1, logHandler.getMessagesString());
    final List<JSONObject> logMessages = parseLogMessages(logHandler);
    assertMessageIs(logMessages.get(0), "request", OperationType.ADD);
}
Also used : TestLogHandler(com.unboundid.util.TestLogHandler) JSONObject(com.unboundid.util.json.JSONObject) InMemoryDirectoryServer(com.unboundid.ldap.listener.InMemoryDirectoryServer) Test(org.testng.annotations.Test)

Example 18 with TestLogHandler

use of com.unboundid.util.TestLogHandler in project ldapsdk by pingidentity.

the class JSONLDAPConnectionLoggerTestCase method testAddLogging.

/**
 * Tests the behavior when logging add operations.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testAddLogging() throws Exception {
    // Get the in-memory directory server instance.
    final InMemoryDirectoryServer ds = getTestDS();
    // Create a logger to use for the test.
    final TestLogHandler logHandler = new TestLogHandler();
    final JSONLDAPConnectionLoggerProperties properties = new JSONLDAPConnectionLoggerProperties();
    final JSONLDAPConnectionLogger logger = new JSONLDAPConnectionLogger(logHandler, properties);
    final LDAPConnectionOptions options = new LDAPConnectionOptions();
    options.setConnectionLogger(logger);
    // Establish a connection and send an add request on it.
    try (LDAPConnection connection = new LDAPConnection(options, "localhost", ds.getListenPort())) {
        connection.add("dn: dc=example,dc=com", "objectClass: top", "objectClass: domain", "dc: example");
    }
    // Make sure that there were five log messages:
    // - Connect
    // - Add request
    // - Add result
    // - Unbind
    // - Disconnect
    assertEquals(logHandler.getMessageCount(), 5, logHandler.getMessagesString());
    final List<JSONObject> logMessages = parseLogMessages(logHandler);
    assertMessageIs(logMessages.get(0), "connect", null);
    assertMessageIs(logMessages.get(1), "request", OperationType.ADD);
    assertMessageIs(logMessages.get(2), "result", OperationType.ADD);
    assertMessageIs(logMessages.get(3), "request", OperationType.UNBIND);
    assertMessageIs(logMessages.get(4), "disconnect", null);
}
Also used : TestLogHandler(com.unboundid.util.TestLogHandler) JSONObject(com.unboundid.util.json.JSONObject) InMemoryDirectoryServer(com.unboundid.ldap.listener.InMemoryDirectoryServer) Test(org.testng.annotations.Test)

Example 19 with TestLogHandler

use of com.unboundid.util.TestLogHandler in project ldapsdk by pingidentity.

the class JSONLDAPConnectionLoggerTestCase method testExtendedOperationLogging.

/**
 * Tests the behavior when logging extended operations.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testExtendedOperationLogging() throws Exception {
    // Get the in-memory directory server instance.
    final InMemoryDirectoryServerConfig config = new InMemoryDirectoryServerConfig("dc=example,dc=com");
    config.addAdditionalBindCredentials("cn=Directory Manager", "password");
    config.addExtendedOperationHandler(new TestIntermediateResponseExtendedOperationHandler("1.2.3.4", "1.2.3.5", "1.2.3.6", 1, 1));
    final InMemoryDirectoryServer ds = new InMemoryDirectoryServer(config);
    ds.startListening();
    try {
        // Create a logger to use for the test.
        final TestLogHandler logHandler = new TestLogHandler();
        final JSONLDAPConnectionLoggerProperties properties = new JSONLDAPConnectionLoggerProperties();
        final JSONLDAPConnectionLogger logger = new JSONLDAPConnectionLogger(logHandler, properties);
        final LDAPConnectionOptions options = new LDAPConnectionOptions();
        options.setConnectionLogger(logger);
        // Establish a connection and send an extended request on it.
        try (LDAPConnection connection = new LDAPConnection(options, "localhost", ds.getListenPort())) {
            assertResultCodeEquals(connection, new ExtendedRequest("1.2.3.4"), ResultCode.SUCCESS);
        }
        // Make sure that there were seven log messages:
        // - Connect
        // - Extended request
        // - Intermediate response with value
        // - Intermediate response without value
        // - Extended result
        // - Unbind
        // - Disconnect
        assertEquals(logHandler.getMessageCount(), 7, logHandler.getMessagesString());
        final List<JSONObject> logMessages = parseLogMessages(logHandler);
        assertMessageIs(logMessages.get(0), "connect", null);
        assertMessageIs(logMessages.get(1), "request", OperationType.EXTENDED);
        assertMessageIs(logMessages.get(2), "intermediate-response", null);
        assertMessageIs(logMessages.get(3), "intermediate-response", null);
        assertMessageIs(logMessages.get(4), "result", OperationType.EXTENDED);
        assertMessageIs(logMessages.get(5), "request", OperationType.UNBIND);
        assertMessageIs(logMessages.get(6), "disconnect", null);
    } finally {
        ds.shutDown(true);
    }
}
Also used : TestLogHandler(com.unboundid.util.TestLogHandler) JSONObject(com.unboundid.util.json.JSONObject) InMemoryDirectoryServer(com.unboundid.ldap.listener.InMemoryDirectoryServer) InMemoryDirectoryServerConfig(com.unboundid.ldap.listener.InMemoryDirectoryServerConfig) TestIntermediateResponseExtendedOperationHandler(com.unboundid.ldap.listener.TestIntermediateResponseExtendedOperationHandler) Test(org.testng.annotations.Test)

Example 20 with TestLogHandler

use of com.unboundid.util.TestLogHandler in project ldapsdk by pingidentity.

the class JSONLDAPConnectionLoggerTestCase method testCompareWithRedactedAttribute.

/**
 * Provides coverage for the case in which a compare request log message
 * targets an attribute whose value should be redacted.
 *
 * Tests the behavior when logging search operations.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testCompareWithRedactedAttribute() throws Exception {
    // Get the in-memory directory server instance.
    final InMemoryDirectoryServer ds = getTestDS(false, false);
    // Create a logger to use for the test.
    final TestLogHandler logHandler = new TestLogHandler();
    final JSONLDAPConnectionLoggerProperties properties = new JSONLDAPConnectionLoggerProperties();
    final JSONLDAPConnectionLogger logger = new JSONLDAPConnectionLogger(logHandler, properties);
    final LDAPConnectionOptions options = new LDAPConnectionOptions();
    options.setConnectionLogger(logger);
    // Generate a log message.
    try (LDAPConnection connection = ds.getConnection()) {
        logger.logCompareRequest(connection, 1, new CompareRequest("uid=test.user,ou=People,dc=example,dc=com", "userPassword", "password"));
    }
    // Make sure that we can decode the message.
    assertEquals(logHandler.getMessageCount(), 1, logHandler.getMessagesString());
    final List<JSONObject> logMessages = parseLogMessages(logHandler);
    assertMessageIs(logMessages.get(0), "request", OperationType.COMPARE);
}
Also used : TestLogHandler(com.unboundid.util.TestLogHandler) JSONObject(com.unboundid.util.json.JSONObject) InMemoryDirectoryServer(com.unboundid.ldap.listener.InMemoryDirectoryServer) Test(org.testng.annotations.Test)

Aggregations

TestLogHandler (com.unboundid.util.TestLogHandler)26 Test (org.testng.annotations.Test)26 InMemoryDirectoryServer (com.unboundid.ldap.listener.InMemoryDirectoryServer)21 JSONObject (com.unboundid.util.json.JSONObject)21 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)6 DN (com.unboundid.ldap.sdk.DN)2 ASN1BitString (com.unboundid.asn1.ASN1BitString)1 ASN1UTF8String (com.unboundid.asn1.ASN1UTF8String)1 InMemoryDirectoryServerConfig (com.unboundid.ldap.listener.InMemoryDirectoryServerConfig)1 TestIntermediateResponseExtendedOperationHandler (com.unboundid.ldap.listener.TestIntermediateResponseExtendedOperationHandler)1 OperationType (com.unboundid.ldap.sdk.OperationType)1 DebugType (com.unboundid.util.DebugType)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 KeyStore (java.security.KeyStore)1 Certificate (java.security.cert.Certificate)1 Level (java.util.logging.Level)1 Logger (java.util.logging.Logger)1