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