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);
}
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);
}
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);
}
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);
}
}
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);
}
Aggregations