use of com.unboundid.util.TestLogHandler in project ldapsdk by pingidentity.
the class JSONLDAPConnectionLoggerTestCase method testSearchFilterWithRedactionNeeded.
/**
* Provides coverage for the case in which a search filter contains attributes
* that do and do not need to be redacted.
*
* Tests the behavior when logging search operations.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testSearchFilterWithRedactionNeeded() 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()) {
final SearchRequest searchRequest = new SearchRequest("dc=example,dc=com", SearchScope.SUB, Filter.createANDFilter(Filter.createORFilter(Filter.createPresenceFilter("userPassword"), Filter.createPresenceFilter("objectClass")), Filter.createORFilter(Filter.createEqualityFilter("userPassword", "password"), Filter.createEqualityFilter("objectClass", "top")), Filter.createORFilter(Filter.createGreaterOrEqualFilter("userPassword", "password"), Filter.createGreaterOrEqualFilter("objectClass", "top")), Filter.createORFilter(Filter.createLessOrEqualFilter("userPassword", "password"), Filter.createLessOrEqualFilter("objectClass", "top")), Filter.createORFilter(Filter.createSubstringFilter("userPassword", "password", null, null), Filter.createSubstringFilter("userPassword", null, new String[] { "password" }, null), Filter.createSubstringFilter("userPassword", null, new String[] { "password", "password" }, null), Filter.createSubstringFilter("userPassword", null, null, "password"), Filter.createSubstringFilter("objectClass", "top", null, null), Filter.createSubstringFilter("objectClass", null, new String[] { "top" }, null), Filter.createSubstringFilter("objectClass", null, new String[] { "top", "top" }, null), Filter.createSubstringFilter("objectClass", null, null, "top")), Filter.createORFilter(Filter.createApproximateMatchFilter("userPassword", "password"), Filter.createApproximateMatchFilter("objectClass", "top")), Filter.createORFilter(Filter.createExtensibleMatchFilter("userPassword", null, false, "password"), Filter.createExtensibleMatchFilter("objectClass", null, false, "top"), Filter.createExtensibleMatchFilter(null, "2.5.13.2", false, "password")), Filter.createNOTFilter(Filter.createEqualityFilter("userPassword", "password"))));
logger.logSearchRequest(connection, 1, searchRequest);
}
// 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.SEARCH);
}
use of com.unboundid.util.TestLogHandler in project ldapsdk by pingidentity.
the class JSONLDAPConnectionLoggerTestCase method testAbandonLogging.
/**
* Tests the behavior when logging abandon requests.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testAbandonLogging() 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 abandon request on it.
try (LDAPConnection connection = new LDAPConnection(options, "localhost", ds.getListenPort())) {
connection.abandon(1);
}
// Make sure that there were four log messages:
// - Connect
// - Abandon
// - Unbind
// - Disconnect
assertEquals(logHandler.getMessageCount(), 4, logHandler.getMessagesString());
final List<JSONObject> logMessages = parseLogMessages(logHandler);
assertMessageIs(logMessages.get(0), "connect", null);
assertMessageIs(logMessages.get(1), "request", OperationType.ABANDON);
assertMessageIs(logMessages.get(2), "request", OperationType.UNBIND);
assertMessageIs(logMessages.get(3), "disconnect", null);
}
use of com.unboundid.util.TestLogHandler in project ldapsdk by pingidentity.
the class JSONLDAPConnectionLoggerTestCase method testGetterMethodsNonDefaults.
/**
* Tests the getter methods with all non-default property values.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testGetterMethodsNonDefaults() throws Exception {
final TestLogHandler logHandler = new TestLogHandler();
final JSONLDAPConnectionLoggerProperties properties = new JSONLDAPConnectionLoggerProperties();
properties.setLogConnects(false);
properties.setLogDisconnects(false);
properties.setLogRequests(false);
properties.setLogFinalResults(false);
properties.setLogSearchEntries(true);
properties.setLogSearchReferences(true);
properties.setLogIntermediateResponses(false);
properties.setOperationTypes();
properties.setIncludeAddAttributeNames(false);
properties.setIncludeAddAttributeValues(true);
properties.setIncludeModifyAttributeNames(false);
properties.setIncludeModifyAttributeValues(true);
properties.setIncludeSearchEntryAttributeNames(false);
properties.setIncludeSearchEntryAttributeValues(true);
properties.setAttributesToRedact();
properties.setIncludeControlOIDs(false);
properties.setSchema(null);
properties.setFlushAfterConnectMessages(false);
properties.setFlushAfterDisconnectMessages(false);
properties.setFlushAfterRequestMessages(true);
properties.setFlushAfterFinalResultMessages(false);
properties.setFlushAfterNonFinalResultMessages(true);
final JSONLDAPConnectionLogger logger = new JSONLDAPConnectionLogger(logHandler, properties);
assertFalse(logger.logConnects());
assertFalse(logger.logDisconnects());
assertFalse(logger.logRequests());
assertFalse(logger.logFinalResults());
assertTrue(logger.logSearchEntries());
assertTrue(logger.logSearchReferences());
assertFalse(logger.logIntermediateResponses());
assertNotNull(logger.getOperationTypes());
assertTrue(logger.getOperationTypes().isEmpty());
assertFalse(logger.includeAddAttributeNames());
assertTrue(logger.includeAddAttributeValues());
assertFalse(logger.includeModifyAttributeNames());
assertTrue(logger.includeModifyAttributeValues());
assertFalse(logger.includeSearchEntryAttributeNames());
assertTrue(logger.includeSearchEntryAttributeValues());
assertNotNull(logger.getAttributesToRedact());
assertTrue(logger.getAttributesToRedact().isEmpty());
assertFalse(logger.includeControlOIDs());
assertNull(logger.getSchema());
assertFalse(logger.flushAfterConnectMessages());
assertFalse(logger.flushAfterDisconnectMessages());
assertTrue(logger.flushAfterRequestMessages());
assertFalse(logger.flushAfterFinalResultMessages());
assertTrue(logger.flushAfterNonFinalResultMessages());
}
use of com.unboundid.util.TestLogHandler in project ldapsdk by pingidentity.
the class JSONLDAPConnectionLoggerTestCase method testGetterMethodsDefaults.
/**
* Tests the getter methods with all the default property values.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testGetterMethodsDefaults() throws Exception {
final TestLogHandler logHandler = new TestLogHandler();
final JSONLDAPConnectionLoggerProperties properties = new JSONLDAPConnectionLoggerProperties();
final JSONLDAPConnectionLogger logger = new JSONLDAPConnectionLogger(logHandler, properties);
assertTrue(logger.logConnects());
assertTrue(logger.logDisconnects());
assertTrue(logger.logRequests());
assertTrue(logger.logFinalResults());
assertFalse(logger.logSearchEntries());
assertFalse(logger.logSearchReferences());
assertTrue(logger.logIntermediateResponses());
assertNotNull(logger.getOperationTypes());
assertFalse(logger.getOperationTypes().isEmpty());
assertEquals(logger.getOperationTypes(), EnumSet.allOf(OperationType.class));
assertTrue(logger.includeAddAttributeNames());
assertFalse(logger.includeAddAttributeValues());
assertTrue(logger.includeModifyAttributeNames());
assertFalse(logger.includeModifyAttributeValues());
assertTrue(logger.includeSearchEntryAttributeNames());
assertFalse(logger.includeSearchEntryAttributeValues());
assertNotNull(logger.getAttributesToRedact());
assertFalse(logger.getAttributesToRedact().isEmpty());
assertEquals(logger.getAttributesToRedact(), StaticUtils.setOf("userPassword", "authPassword", "unicodePwd"));
assertTrue(logger.includeControlOIDs());
assertNotNull(logger.getSchema());
assertTrue(logger.flushAfterConnectMessages());
assertTrue(logger.flushAfterDisconnectMessages());
assertFalse(logger.flushAfterRequestMessages());
assertTrue(logger.flushAfterFinalResultMessages());
assertFalse(logger.flushAfterNonFinalResultMessages());
}
use of com.unboundid.util.TestLogHandler in project ldapsdk by pingidentity.
the class JSONLDAPConnectionLoggerTestCase method testModifyDNLogging.
/**
* Tests the behavior when logging modify DN operations.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testModifyDNLogging() throws Exception {
// Get the in-memory directory server instance.
final InMemoryDirectoryServer ds = getTestDS(true, true);
ds.add("dn: ou=Users,dc=example,dc=com", "objectClass: top", "objectClass: organizationalUnit", "ou: Users");
// 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.modifyDN("uid=test.user,ou=People,dc=example,dc=com", "cn=Test User", false, "ou=Users,dc=example,dc=com");
}
// Make sure that there were five log messages:
// - Connect
// - Modify DN request
// - Modify DN 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_DN);
assertMessageIs(logMessages.get(2), "result", OperationType.MODIFY_DN);
assertMessageIs(logMessages.get(3), "request", OperationType.UNBIND);
assertMessageIs(logMessages.get(4), "disconnect", null);
}
Aggregations