use of com.unboundid.util.ByteStringBuffer in project ldapsdk by pingidentity.
the class LDIFChangeRecord method encodeControlString.
/**
* Encodes a string representation of the provided control for use in the
* LDIF representation of the change record.
*
* @param c The control to be encoded.
*
* @return The string representation of the control.
*/
@NotNull()
static ASN1OctetString encodeControlString(@NotNull final Control c) {
final ByteStringBuffer buffer = new ByteStringBuffer();
buffer.append(c.getOID());
if (c.isCritical()) {
buffer.append(" true");
} else {
buffer.append(" false");
}
final ASN1OctetString value = c.getValue();
if (value != null) {
LDIFWriter.encodeValue(value, buffer);
}
return buffer.toByteString().toASN1OctetString();
}
use of com.unboundid.util.ByteStringBuffer in project ldapsdk by pingidentity.
the class SummarizeAccessLogTestCase method testEncryptedFileWithPromptCorrect.
/**
* Provides test coverage for the summarize-access-log tool with an encrypted
* file when the correct encryption passphrase is entered via an interactive
* prompt.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testEncryptedFileWithPromptCorrect() throws Exception {
final String[] args = { encryptedFile.getAbsolutePath() };
final ByteStringBuffer buffer = new ByteStringBuffer();
buffer.append(StaticUtils.EOL_BYTES);
buffer.append("password");
buffer.append(StaticUtils.EOL_BYTES);
final ByteArrayInputStream in = new ByteArrayInputStream(buffer.toByteArray());
final BufferedReader passwordReader = new BufferedReader(new InputStreamReader(in));
try {
PasswordReader.setTestReader(passwordReader);
final ResultCode rc = SummarizeAccessLog.main(args, null, null);
assertEquals(rc, ResultCode.SUCCESS);
} finally {
PasswordReader.setTestReader(null);
}
}
use of com.unboundid.util.ByteStringBuffer in project ldapsdk by pingidentity.
the class StringLogFieldSyntaxTestCase method testTextLogMethods.
/**
* Tests the methods that may be used for logging text-formatted messages.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testTextLogMethods() throws Exception {
final StringLogFieldSyntax syntax = new StringLogFieldSyntax(10);
final ByteStringBuffer buffer = new ByteStringBuffer();
syntax.logSanitizedFieldToTextFormattedLog("abc", "foo", buffer);
assertEquals(buffer.toString(), " abc=\"foo\"");
buffer.clear();
syntax.logSanitizedFieldToTextFormattedLog("def", "ThisIsALongerValue", buffer);
assertEquals(buffer.toString(), " def=\"ThisIsALon{8 more characters}\"");
buffer.clear();
syntax.logCompletelyRedactedFieldToTextFormattedLog("ghi", buffer);
assertEquals(buffer.toString(), " ghi=\"{REDACTED}\"");
buffer.clear();
syntax.logRedactedComponentsFieldToTextFormattedLog("jkl", "ThisIsALongerValue", buffer);
assertEquals(buffer.toString(), " jkl=\"{REDACTED}\"");
buffer.clear();
final byte[] pepper = StaticUtils.randomBytes(8, false);
syntax.logCompletelyTokenizedFieldToTextFormattedLog("mno", "ThisIsALongerValue", pepper, buffer);
final String completelyTokenizedString = buffer.toString();
assertTrue(completelyTokenizedString.startsWith(" mno=\"{TOKENIZED:"));
assertTrue(completelyTokenizedString.endsWith("}\""));
buffer.clear();
syntax.logTokenizedComponentsFieldToTextFormattedLog("pqr", "ThisIsALongerValue", pepper, buffer);
final String tokenizedComponentsString = buffer.toString();
assertTrue(tokenizedComponentsString.startsWith(" pqr=\"{TOKENIZED:"));
assertEquals(tokenizedComponentsString, " pqr=\"" + completelyTokenizedString.substring(6));
}
use of com.unboundid.util.ByteStringBuffer in project ldapsdk by pingidentity.
the class DNLogFieldSyntaxTestCase method testTextLogMethods.
/**
* Tests the methods that may be used for logging text-formatted messages.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testTextLogMethods() 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 ByteStringBuffer buffer = new ByteStringBuffer();
syntax.logSanitizedFieldToTextFormattedLog("abc", new DN("uid=test.user,ou=People,dc=example,dc=com"), buffer);
assertEquals(buffer.toString(), " abc=\"uid=test.user,ou=People,dc=example,dc=com\"");
buffer.clear();
syntax.logCompletelyRedactedFieldToTextFormattedLog("def", buffer);
assertEquals(buffer.toString(), " def=\"redacted={REDACTED}\"");
buffer.clear();
syntax.logRedactedComponentsFieldToTextFormattedLog("ghi", new DN("uid=test.user,ou=People,dc=example,dc=com"), buffer);
assertEquals(buffer.toString(), " ghi=\"uid={REDACTED},ou=People,dc=example,dc=com\"");
buffer.clear();
final byte[] pepper = StaticUtils.randomBytes(8, false);
syntax.logCompletelyTokenizedFieldToTextFormattedLog("jkl", new DN("uid=test.user,ou=People,dc=example,dc=com"), pepper, buffer);
final String completelyTokenizedString = buffer.toString();
assertTrue(completelyTokenizedString.startsWith(" jkl=\"tokenized={TOKENIZED:"));
assertTrue(completelyTokenizedString.endsWith("}\""));
buffer.clear();
syntax.logTokenizedComponentsFieldToTextFormattedLog("mno", new DN("uid=test.user,ou=People,dc=example,dc=com"), pepper, buffer);
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.ByteStringBuffer in project ldapsdk by pingidentity.
the class FilterLogFieldSyntaxTestCase method testTextLogMethods.
/**
* Tests the methods that may be used for logging text-formatted messages.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testTextLogMethods() 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 ByteStringBuffer buffer = new ByteStringBuffer();
syntax.logSanitizedFieldToTextFormattedLog("abc", Filter.createEqualityFilter("uid", "test.user"), buffer);
assertEquals(buffer.toString(), " abc=\"(uid=test.user)\"");
buffer.clear();
syntax.logCompletelyRedactedFieldToTextFormattedLog("def", buffer);
assertEquals(buffer.toString(), " def=\"(redacted={REDACTED})\"");
buffer.clear();
syntax.logRedactedComponentsFieldToTextFormattedLog("ghi", Filter.createEqualityFilter("uid", "test.user"), buffer);
assertEquals(buffer.toString(), " ghi=\"(uid={REDACTED})\"");
buffer.clear();
final byte[] pepper = StaticUtils.randomBytes(8, false);
syntax.logCompletelyTokenizedFieldToTextFormattedLog("jkl", Filter.createEqualityFilter("uid", "test.user"), pepper, buffer);
final String completelyTokenizedString = buffer.toString();
assertTrue(completelyTokenizedString.startsWith(" jkl=\"(tokenized={TOKENIZED:"));
assertTrue(completelyTokenizedString.endsWith("})\""));
buffer.clear();
syntax.logTokenizedComponentsFieldToTextFormattedLog("mno", Filter.createEqualityFilter("uid", "test.user"), pepper, buffer);
final String tokenizedComponentsString = buffer.toString();
assertTrue(tokenizedComponentsString.startsWith(" mno=\"(uid={TOKENIZED:"));
assertTrue(tokenizedComponentsString.endsWith("})\""));
}
Aggregations