Search in sources :

Example 21 with JSONBuffer

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

the class StringLogFieldSyntaxTestCase 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 StringLogFieldSyntax syntax = new StringLogFieldSyntax(10);
    final JSONBuffer buffer = new JSONBuffer();
    buffer.beginObject();
    syntax.logSanitizedFieldToJSONFormattedLog("abc", "ThisIsALongerValue", buffer);
    buffer.endObject();
    assertEquals(buffer.toString(), "{ \"abc\":\"ThisIsALon{8 more characters}\" }");
    buffer.clear();
    buffer.beginObject();
    syntax.logCompletelyRedactedFieldToJSONFormattedLog("def", buffer);
    buffer.endObject();
    assertEquals(buffer.toString(), "{ \"def\":\"{REDACTED}\" }");
    buffer.clear();
    buffer.beginObject();
    syntax.logRedactedComponentsFieldToJSONFormattedLog("ghi", "ThisIsALongerValue", buffer);
    buffer.endObject();
    assertEquals(buffer.toString(), "{ \"ghi\":\"{REDACTED}\" }");
    buffer.clear();
    buffer.beginObject();
    final byte[] pepper = StaticUtils.randomBytes(8, false);
    syntax.logCompletelyTokenizedFieldToJSONFormattedLog("jkl", "ThisIsALongerValue", pepper, buffer);
    buffer.endObject();
    final String completelyTokenizedString = buffer.toString();
    assertTrue(completelyTokenizedString.startsWith("{ \"jkl\":\"{TOKENIZED:"));
    assertTrue(completelyTokenizedString.endsWith("}\" }"));
    buffer.clear();
    buffer.beginObject();
    syntax.logTokenizedComponentsFieldToJSONFormattedLog("mno", "ThisIsALongerValue", pepper, buffer);
    buffer.endObject();
    final String tokenizedComponentsString = buffer.toString();
    assertTrue(tokenizedComponentsString.startsWith("{ \"mno\":\"{TOKENIZED:"));
    assertEquals(tokenizedComponentsString, "{ \"mno\":" + completelyTokenizedString.substring(8));
}
Also used : JSONBuffer(com.unboundid.util.json.JSONBuffer) Test(org.testng.annotations.Test)

Example 22 with JSONBuffer

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

the class FilterLogFieldSyntaxTestCase 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 FilterLogFieldSyntax syntax = new FilterLogFieldSyntax(100, null, includedAttributes, excludedAttributes);
    final JSONBuffer buffer = new JSONBuffer();
    syntax.logSanitizedValueToJSONFormattedLog(Filter.createEqualityFilter("uid", "test.user"), buffer);
    assertEquals(buffer.toString(), "\"(uid=test.user)\"");
    buffer.clear();
    syntax.logCompletelyRedactedValueToJSONFormattedLog(buffer);
    assertEquals(buffer.toString(), "\"(redacted={REDACTED})\"");
    buffer.clear();
    syntax.logRedactedComponentsValueToJSONFormattedLog(Filter.createEqualityFilter("uid", "test.user"), buffer);
    assertEquals(buffer.toString(), "\"(uid={REDACTED})\"");
    buffer.clear();
    final byte[] pepper = StaticUtils.randomBytes(8, false);
    syntax.logCompletelyTokenizedValueToJSONFormattedLog(Filter.createEqualityFilter("uid", "test.user"), pepper, buffer);
    final String completelyTokenizedString = buffer.toString();
    assertTrue(completelyTokenizedString.startsWith("\"(tokenized={TOKENIZED:"));
    assertTrue(completelyTokenizedString.endsWith("})\""));
    buffer.clear();
    syntax.logTokenizedComponentsValueToJSONFormattedLog(Filter.createEqualityFilter("uid", "test.user"), pepper, buffer);
    final String tokenizedComponentsString = buffer.toString();
    assertTrue(tokenizedComponentsString.startsWith("\"(uid={TOKENIZED:"));
    assertTrue(tokenizedComponentsString.endsWith("})\""));
}
Also used : JSONBuffer(com.unboundid.util.json.JSONBuffer) Test(org.testng.annotations.Test)

Example 23 with JSONBuffer

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

the class FloatingPointLogFieldSyntaxTestCase 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 FloatingPointLogFieldSyntax syntax = FloatingPointLogFieldSyntax.getInstance();
    final JSONBuffer buffer = new JSONBuffer();
    buffer.beginObject();
    syntax.logSanitizedFieldToJSONFormattedLog("abc", 1.5d, buffer);
    buffer.endObject();
    assertEquals(buffer.toString(), "{ \"abc\":1.500 }");
    buffer.clear();
    buffer.beginObject();
    syntax.logCompletelyRedactedFieldToJSONFormattedLog("def", buffer);
    buffer.endObject();
    assertEquals(buffer.toString(), "{ \"def\":-999999.999999 }");
    buffer.clear();
    buffer.beginObject();
    syntax.logRedactedComponentsFieldToJSONFormattedLog("ghi", 1.5d, buffer);
    buffer.endObject();
    assertEquals(buffer.toString(), "{ \"ghi\":-999999.999999 }");
    buffer.clear();
    buffer.beginObject();
    final byte[] pepper = StaticUtils.randomBytes(8, false);
    syntax.logCompletelyTokenizedFieldToJSONFormattedLog("jkl", 1.5d, pepper, buffer);
    buffer.endObject();
    final String completelyTokenizedString = buffer.toString();
    assertTrue(completelyTokenizedString.startsWith("{ \"jkl\":-999999."));
    assertTrue(completelyTokenizedString.endsWith(" }"));
    assertFalse(completelyTokenizedString.equals("{ \"jkl\":-999999.999999 }"));
    buffer.clear();
    buffer.beginObject();
    syntax.logTokenizedComponentsFieldToJSONFormattedLog("mno", 1.5d, pepper, buffer);
    buffer.endObject();
    final String tokenizedComponentsString = buffer.toString();
    assertTrue(tokenizedComponentsString.startsWith("{ \"mno\":-999999."));
    assertTrue(tokenizedComponentsString.endsWith(" }"));
    assertEquals(tokenizedComponentsString, "{ \"mno\"" + completelyTokenizedString.substring(7));
}
Also used : JSONBuffer(com.unboundid.util.json.JSONBuffer) Test(org.testng.annotations.Test)

Example 24 with JSONBuffer

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

the class GeneralizedTimeLogFieldSyntaxTestCase 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 GeneralizedTimeLogFieldSyntax syntax = GeneralizedTimeLogFieldSyntax.getInstance();
    final Date now = new Date();
    final JSONBuffer buffer = new JSONBuffer();
    syntax.logSanitizedValueToJSONFormattedLog(now, buffer);
    assertEquals(buffer.toString(), '"' + StaticUtils.encodeGeneralizedTime(now) + '"');
    buffer.clear();
    syntax.logCompletelyRedactedValueToJSONFormattedLog(buffer);
    assertEquals(buffer.toString(), "\"99990101000000.000Z\"");
    buffer.clear();
    syntax.logRedactedComponentsValueToJSONFormattedLog(now, buffer);
    assertEquals(buffer.toString(), "\"99990101000000.000Z\"");
    buffer.clear();
    final byte[] pepper = StaticUtils.randomBytes(8, false);
    syntax.logCompletelyTokenizedValueToJSONFormattedLog(now, pepper, buffer);
    final String completelyTokenizedString = buffer.toString();
    assertTrue(completelyTokenizedString.startsWith("\"8888"));
    assertTrue(completelyTokenizedString.endsWith("Z\""));
    buffer.clear();
    syntax.logTokenizedComponentsValueToJSONFormattedLog(now, pepper, buffer);
    final String tokenizedComponentsString = buffer.toString();
    assertTrue(tokenizedComponentsString.startsWith("\"8888"));
    assertEquals(tokenizedComponentsString, completelyTokenizedString);
}
Also used : JSONBuffer(com.unboundid.util.json.JSONBuffer) Date(java.util.Date) Test(org.testng.annotations.Test)

Example 25 with JSONBuffer

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

the class IntegerLogFieldSyntaxTestCase 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 IntegerLogFieldSyntax syntax = IntegerLogFieldSyntax.getInstance();
    final JSONBuffer buffer = new JSONBuffer();
    buffer.beginObject();
    syntax.logSanitizedFieldToJSONFormattedLog("abc", 1234L, buffer);
    buffer.endObject();
    assertEquals(buffer.toString(), "{ \"abc\":1234 }");
    buffer.clear();
    buffer.beginObject();
    syntax.logCompletelyRedactedFieldToJSONFormattedLog("def", buffer);
    buffer.endObject();
    assertEquals(buffer.toString(), "{ \"def\":-999999999999999999 }");
    buffer.clear();
    buffer.beginObject();
    syntax.logRedactedComponentsFieldToJSONFormattedLog("ghi", 1234L, buffer);
    buffer.endObject();
    assertEquals(buffer.toString(), "{ \"ghi\":-999999999999999999 }");
    buffer.clear();
    buffer.beginObject();
    final byte[] pepper = StaticUtils.randomBytes(8, false);
    syntax.logCompletelyTokenizedFieldToJSONFormattedLog("jkl", 1234L, pepper, buffer);
    buffer.endObject();
    final String completelyTokenizedString = buffer.toString();
    assertTrue(completelyTokenizedString.startsWith("{ \"jkl\":-999999999"));
    assertTrue(completelyTokenizedString.endsWith(" }"));
    assertFalse(completelyTokenizedString.equals("{ \"jkl\":-999999999999999999 }"));
    buffer.clear();
    buffer.beginObject();
    syntax.logTokenizedComponentsFieldToJSONFormattedLog("mno", 1234L, pepper, buffer);
    buffer.endObject();
    final String tokenizedComponentsString = buffer.toString();
    assertTrue(tokenizedComponentsString.startsWith("{ \"mno\":-999999999"));
    assertTrue(tokenizedComponentsString.endsWith(" }"));
    assertEquals(tokenizedComponentsString, "{ \"mno\"" + completelyTokenizedString.substring(7));
}
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