Search in sources :

Example 41 with JSONBuffer

use of com.unboundid.util.json.JSONBuffer in project ldapsdk by pingidentity.

the class CommaDelimitedStringListLogFieldSyntaxTestCase method testJSONValueLogMethods.

/**
 * Tests the methods that may be used for logging JSON-formatted values
 * (without field names).
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testJSONValueLogMethods() throws Exception {
    final CommaDelimitedStringListLogFieldSyntax syntax = new CommaDelimitedStringListLogFieldSyntax(10);
    final JSONBuffer buffer = new JSONBuffer();
    syntax.logSanitizedValueToJSONFormattedLog(Arrays.asList("short", "LongEnoughToTruncate"), buffer);
    assertEquals(buffer.toString(), "\"short,LongEnough{10 more characters}\"");
    buffer.clear();
    syntax.logCompletelyRedactedValueToJSONFormattedLog(buffer);
    assertEquals(buffer.toString(), "\"{REDACTED}\"");
    buffer.clear();
    syntax.logRedactedComponentsValueToJSONFormattedLog(Arrays.asList("short", "LongEnoughToTruncate"), buffer);
    assertEquals(buffer.toString(), "\"{REDACTED},{REDACTED}\"");
    buffer.clear();
    final byte[] pepper = StaticUtils.randomBytes(8, false);
    syntax.logCompletelyTokenizedValueToJSONFormattedLog(Arrays.asList("short", "LongEnoughToTruncate"), pepper, buffer);
    final String completelyTokenizedString = buffer.toString();
    assertTrue(completelyTokenizedString.startsWith("\"{TOKENIZED:"));
    assertFalse(completelyTokenizedString.contains("},{TOKENIZED:"));
    assertTrue(completelyTokenizedString.endsWith("}\""));
    buffer.clear();
    syntax.logTokenizedComponentsValueToJSONFormattedLog(Arrays.asList("short", "LongEnoughToTruncate"), pepper, buffer);
    final String tokenizedComponentsString = buffer.toString();
    assertTrue(tokenizedComponentsString.startsWith("\"{TOKENIZED:"));
    assertTrue(tokenizedComponentsString.contains("},{TOKENIZED:"));
    assertTrue(tokenizedComponentsString.endsWith("}\""));
}
Also used : JSONBuffer(com.unboundid.util.json.JSONBuffer) Test(org.testng.annotations.Test)

Example 42 with JSONBuffer

use of com.unboundid.util.json.JSONBuffer in project ldapsdk by pingidentity.

the class CommaDelimitedStringListLogFieldSyntaxTestCase method testJSONLogMethods.

/**
 * Tests the methods that may be used for logging JSON-formatted messages.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testJSONLogMethods() throws Exception {
    final CommaDelimitedStringListLogFieldSyntax syntax = new CommaDelimitedStringListLogFieldSyntax(10);
    final JSONBuffer buffer = new JSONBuffer();
    buffer.beginObject();
    syntax.logSanitizedFieldToJSONFormattedLog("abc", Arrays.asList("short", "LongEnoughToTruncate"), buffer);
    buffer.endObject();
    assertEquals(buffer.toString(), "{ \"abc\":\"short,LongEnough{10 more characters}\" }");
    buffer.clear();
    buffer.beginObject();
    syntax.logCompletelyRedactedFieldToJSONFormattedLog("def", buffer);
    buffer.endObject();
    assertEquals(buffer.toString(), "{ \"def\":\"{REDACTED}\" }");
    buffer.clear();
    buffer.beginObject();
    syntax.logRedactedComponentsFieldToJSONFormattedLog("ghi", Arrays.asList("short", "LongEnoughToTruncate"), buffer);
    buffer.endObject();
    assertEquals(buffer.toString(), "{ \"ghi\":\"{REDACTED},{REDACTED}\" }");
    buffer.clear();
    buffer.beginObject();
    final byte[] pepper = StaticUtils.randomBytes(8, false);
    syntax.logCompletelyTokenizedFieldToJSONFormattedLog("jkl", Arrays.asList("short", "LongEnoughToTruncate"), pepper, buffer);
    buffer.endObject();
    final String completelyTokenizedString = buffer.toString();
    assertTrue(completelyTokenizedString.startsWith("{ \"jkl\":\"{TOKENIZED:"));
    assertFalse(completelyTokenizedString.contains("},{TOKENIZED:"));
    assertTrue(completelyTokenizedString.endsWith("}\" }"));
    buffer.clear();
    buffer.beginObject();
    syntax.logTokenizedComponentsFieldToJSONFormattedLog("mno", Arrays.asList("short", "LongEnoughToTruncate"), pepper, buffer);
    buffer.endObject();
    final String tokenizedComponentsString = buffer.toString();
    assertTrue(tokenizedComponentsString.startsWith("{ \"mno\":\"{TOKENIZED:"));
    assertTrue(tokenizedComponentsString.contains("},{TOKENIZED:"));
    assertTrue(tokenizedComponentsString.endsWith("}\" }"));
}
Also used : JSONBuffer(com.unboundid.util.json.JSONBuffer) Test(org.testng.annotations.Test)

Example 43 with JSONBuffer

use of com.unboundid.util.json.JSONBuffer in project ldapsdk by pingidentity.

the class DNLogFieldSyntaxTestCase method testJSONLogMethods.

/**
 * Tests the methods that may be used for logging JSON-formatted messages.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testJSONLogMethods() throws Exception {
    final Set<String> includedAttributes = StaticUtils.setOf("uid");
    final Set<String> excludedAttributes = Collections.emptySet();
    final DNLogFieldSyntax syntax = new DNLogFieldSyntax(100, null, includedAttributes, excludedAttributes);
    final JSONBuffer buffer = new JSONBuffer();
    buffer.beginObject();
    syntax.logSanitizedFieldToJSONFormattedLog("abc", new DN("uid=test.user,ou=People,dc=example,dc=com"), buffer);
    buffer.endObject();
    assertEquals(buffer.toString(), "{ \"abc\":\"uid=test.user,ou=People,dc=example,dc=com\" }");
    buffer.clear();
    buffer.beginObject();
    syntax.logCompletelyRedactedFieldToJSONFormattedLog("def", buffer);
    buffer.endObject();
    assertEquals(buffer.toString(), "{ \"def\":\"redacted={REDACTED}\" }");
    buffer.clear();
    buffer.beginObject();
    syntax.logRedactedComponentsFieldToJSONFormattedLog("ghi", new DN("uid=test.user,ou=People,dc=example,dc=com"), buffer);
    buffer.endObject();
    assertEquals(buffer.toString(), "{ \"ghi\":\"uid={REDACTED},ou=People,dc=example,dc=com\" }");
    buffer.clear();
    buffer.beginObject();
    final byte[] pepper = StaticUtils.randomBytes(8, false);
    syntax.logCompletelyTokenizedFieldToJSONFormattedLog("jkl", new DN("uid=test.user,ou=People,dc=example,dc=com"), pepper, buffer);
    buffer.endObject();
    final String completelyTokenizedString = buffer.toString();
    assertTrue(completelyTokenizedString.startsWith("{ \"jkl\":\"tokenized={TOKENIZED:"));
    assertTrue(completelyTokenizedString.endsWith("}\" }"));
    buffer.clear();
    buffer.beginObject();
    syntax.logTokenizedComponentsFieldToJSONFormattedLog("mno", new DN("uid=test.user,ou=People,dc=example,dc=com"), pepper, buffer);
    buffer.endObject();
    final String tokenizedComponentsString = buffer.toString();
    assertTrue(tokenizedComponentsString.startsWith("{ \"mno\":\"uid={TOKENIZED:"));
    assertTrue(tokenizedComponentsString.endsWith("},ou=People,dc=example,dc=com\" }"));
}
Also used : JSONBuffer(com.unboundid.util.json.JSONBuffer) RDN(com.unboundid.ldap.sdk.RDN) DN(com.unboundid.ldap.sdk.DN) Test(org.testng.annotations.Test)

Example 44 with JSONBuffer

use of com.unboundid.util.json.JSONBuffer in project ldapsdk by pingidentity.

the class DNLogFieldSyntaxTestCase method testJSONValueLogMethods.

/**
 * Tests the methods that may be used for logging JSON-formatted values
 * (without field names).
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testJSONValueLogMethods() throws Exception {
    final Set<String> includedAttributes = StaticUtils.setOf("uid");
    final Set<String> excludedAttributes = Collections.emptySet();
    final DNLogFieldSyntax syntax = new DNLogFieldSyntax(100, null, includedAttributes, excludedAttributes);
    final JSONBuffer buffer = new JSONBuffer();
    syntax.logSanitizedValueToJSONFormattedLog(new DN("uid=test.user,ou=People,dc=example,dc=com"), buffer);
    assertEquals(buffer.toString(), "\"uid=test.user,ou=People,dc=example,dc=com\"");
    buffer.clear();
    syntax.logCompletelyRedactedValueToJSONFormattedLog(buffer);
    assertEquals(buffer.toString(), "\"redacted={REDACTED}\"");
    buffer.clear();
    syntax.logRedactedComponentsValueToJSONFormattedLog(new DN("uid=test.user,ou=People,dc=example,dc=com"), buffer);
    assertEquals(buffer.toString(), "\"uid={REDACTED},ou=People,dc=example,dc=com\"");
    buffer.clear();
    final byte[] pepper = StaticUtils.randomBytes(8, false);
    syntax.logCompletelyTokenizedValueToJSONFormattedLog(new DN("uid=test.user,ou=People,dc=example,dc=com"), pepper, buffer);
    final String completelyTokenizedString = buffer.toString();
    assertTrue(completelyTokenizedString.startsWith("\"tokenized={TOKENIZED:"));
    assertTrue(completelyTokenizedString.endsWith("}\""));
    buffer.clear();
    syntax.logTokenizedComponentsValueToJSONFormattedLog(new DN("uid=test.user,ou=People,dc=example,dc=com"), pepper, buffer);
    final String tokenizedComponentsString = buffer.toString();
    assertTrue(tokenizedComponentsString.startsWith("\"uid={TOKENIZED:"));
    assertTrue(tokenizedComponentsString.endsWith("},ou=People,dc=example,dc=com\""));
}
Also used : JSONBuffer(com.unboundid.util.json.JSONBuffer) RDN(com.unboundid.ldap.sdk.RDN) DN(com.unboundid.ldap.sdk.DN) Test(org.testng.annotations.Test)

Example 45 with JSONBuffer

use of com.unboundid.util.json.JSONBuffer in project ldapsdk by pingidentity.

the class FilterLogFieldSyntaxTestCase method testJSONLogMethods.

/**
 * Tests the methods that may be used for logging JSON-formatted messages.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testJSONLogMethods() throws Exception {
    final Set<String> includedAttributes = StaticUtils.setOf("uid");
    final Set<String> excludedAttributes = Collections.emptySet();
    final FilterLogFieldSyntax syntax = new FilterLogFieldSyntax(100, null, includedAttributes, excludedAttributes);
    final JSONBuffer buffer = new JSONBuffer();
    buffer.beginObject();
    syntax.logSanitizedFieldToJSONFormattedLog("abc", Filter.createEqualityFilter("uid", "test.user"), buffer);
    buffer.endObject();
    assertEquals(buffer.toString(), "{ \"abc\":\"(uid=test.user)\" }");
    buffer.clear();
    buffer.beginObject();
    syntax.logCompletelyRedactedFieldToJSONFormattedLog("def", buffer);
    buffer.endObject();
    assertEquals(buffer.toString(), "{ \"def\":\"(redacted={REDACTED})\" }");
    buffer.clear();
    buffer.beginObject();
    syntax.logRedactedComponentsFieldToJSONFormattedLog("ghi", Filter.createEqualityFilter("uid", "test.user"), buffer);
    buffer.endObject();
    assertEquals(buffer.toString(), "{ \"ghi\":\"(uid={REDACTED})\" }");
    buffer.clear();
    buffer.beginObject();
    final byte[] pepper = StaticUtils.randomBytes(8, false);
    syntax.logCompletelyTokenizedFieldToJSONFormattedLog("jkl", Filter.createEqualityFilter("uid", "test.user"), pepper, buffer);
    buffer.endObject();
    final String completelyTokenizedString = buffer.toString();
    assertTrue(completelyTokenizedString.startsWith("{ \"jkl\":\"(tokenized={TOKENIZED:"));
    assertTrue(completelyTokenizedString.endsWith("})\" }"));
    buffer.clear();
    buffer.beginObject();
    syntax.logTokenizedComponentsFieldToJSONFormattedLog("mno", Filter.createEqualityFilter("uid", "test.user"), pepper, buffer);
    buffer.endObject();
    final String tokenizedComponentsString = buffer.toString();
    assertTrue(tokenizedComponentsString.startsWith("{ \"mno\":\"(uid={TOKENIZED:"));
    assertTrue(tokenizedComponentsString.endsWith("})\" }"));
}
Also used : JSONBuffer(com.unboundid.util.json.JSONBuffer) Test(org.testng.annotations.Test)

Aggregations

JSONBuffer (com.unboundid.util.json.JSONBuffer)73 Test (org.testng.annotations.Test)20 NotNull (com.unboundid.util.NotNull)16 LogRecord (java.util.logging.LogRecord)12 LDAPMessage (com.unboundid.ldap.protocol.LDAPMessage)8 Date (java.util.Date)5 LDAPException (com.unboundid.ldap.sdk.LDAPException)3 LDAPRuntimeException (com.unboundid.ldap.sdk.LDAPRuntimeException)3 JSONException (com.unboundid.util.json.JSONException)3 DN (com.unboundid.ldap.sdk.DN)2 RDN (com.unboundid.ldap.sdk.RDN)2 JSONField (com.unboundid.util.json.JSONField)2 JSONObject (com.unboundid.util.json.JSONObject)2 JSONString (com.unboundid.util.json.JSONString)2 AddResponseProtocolOp (com.unboundid.ldap.protocol.AddResponseProtocolOp)1 BindResponseProtocolOp (com.unboundid.ldap.protocol.BindResponseProtocolOp)1 CompareResponseProtocolOp (com.unboundid.ldap.protocol.CompareResponseProtocolOp)1 DeleteResponseProtocolOp (com.unboundid.ldap.protocol.DeleteResponseProtocolOp)1 ExtendedResponseProtocolOp (com.unboundid.ldap.protocol.ExtendedResponseProtocolOp)1 ModifyDNResponseProtocolOp (com.unboundid.ldap.protocol.ModifyDNResponseProtocolOp)1