Search in sources :

Example 1 with TestLogHandler

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

the class JSONLDAPConnectionLoggerTestCase method testModifyWithAllDetailsIncluded.

/**
 * Provides coverage for the case in which a modify request log message
 * contains modifications and both names and values are to be logged.
 *
 * Tests the behavior when logging search operations.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testModifyWithAllDetailsIncluded() 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.setIncludeModifyAttributeNames(true);
    properties.setIncludeModifyAttributeValues(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()) {
        connection.setConnectionName("The connection name");
        connection.setConnectionPoolName("The connection pool name");
        final ModifyRequest modifyRequest = new ModifyRequest("dn: uid=test.user,ou=People,dc=example,dc=com", "changetype: modify", "replace: userPassword", "userPassword: newPassword", "-", "replace: authpassword", "authpassword: anotherNewPassword", "-", "replace: description", "-", "delete: givenName", "-", "add: givenName", "givenName: Foo", "-", "delete: givenName", "givenName: Foo", "-", "add: givenName", "givenName: Test", "-", "increment: intValueAttr", "intValueAttr: 1", "-");
        logger.logModifyRequest(connection, 1, modifyRequest);
    }
    // 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.MODIFY);
}
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 2 with TestLogHandler

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

the class JSONLDAPConnectionLoggerTestCase method testModifyLogging.

/**
 * Tests the behavior when logging modify operations.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testModifyLogging() throws Exception {
    // Get the in-memory directory server instance.
    final InMemoryDirectoryServer ds = getTestDS(true, 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);
    // Establish a connection and send a modify request on it.
    try (LDAPConnection connection = new LDAPConnection(options, "localhost", ds.getListenPort())) {
        connection.modify("dn: dc=example,dc=com", "changetype: modify", "replace: description", "description: foo");
    }
    // Make sure that there were five log messages:
    // - Connect
    // - Modify request
    // - Modify 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.MODIFY);
    assertMessageIs(logMessages.get(2), "result", OperationType.MODIFY);
    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 3 with TestLogHandler

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

the class JSONLDAPConnectionLoggerTestCase method testDisconnectLoggingAllElements.

/**
 * Provides coverage for the case in which a disconnect log message contains
 * all elements.
 *
 * Tests the behavior when logging search operations.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testDisconnectLoggingAllElements() 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.logDisconnect(connection, "localhost", ds.getListenPort(), DisconnectType.OTHER, "Testing disconnect logging", new Exception());
    }
    // Make sure that we can decode the message.
    assertEquals(logHandler.getMessageCount(), 1, logHandler.getMessagesString());
    final List<JSONObject> logMessages = parseLogMessages(logHandler);
    assertMessageIs(logMessages.get(0), "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 4 with TestLogHandler

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

the class JSONLDAPConnectionLoggerTestCase method testCompareLogging.

/**
 * Tests the behavior when logging compare operations.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testCompareLogging() throws Exception {
    // Get the in-memory directory server instance.
    final InMemoryDirectoryServer ds = getTestDS(true, 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);
    // Establish a connection and send a compare request on it.
    try (LDAPConnection connection = new LDAPConnection(options, "localhost", ds.getListenPort())) {
        assertTrue(connection.compare("dc=example,dc=com", "dc", "example").compareMatched());
    }
    // Make sure that there were five log messages:
    // - Connect
    // - Compare request
    // - Compare 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.COMPARE);
    assertMessageIs(logMessages.get(2), "result", OperationType.COMPARE);
    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 5 with TestLogHandler

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

the class JSONLDAPConnectionLoggerTestCase method testAbandonWithControls.

/**
 * Provides coverage for the case in which an abandon request includes
 * controls, which will  be processed as a list.
 *
 * Tests the behavior when logging search operations.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testAbandonWithControls() 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.logAbandonRequest(connection, 2, 1, Arrays.asList(new Control("1.2.3.4", false, null), new Control("1.2.3.5", true, new ASN1OctetString("foo"))));
    }
    // 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.ABANDON);
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) 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