Search in sources :

Example 16 with ByteStringBuffer

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();
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) ByteStringBuffer(com.unboundid.util.ByteStringBuffer) NotNull(com.unboundid.util.NotNull)

Example 17 with ByteStringBuffer

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);
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) ByteArrayInputStream(java.io.ByteArrayInputStream) BufferedReader(java.io.BufferedReader) JSONString(com.unboundid.util.json.JSONString) ByteStringBuffer(com.unboundid.util.ByteStringBuffer) ResultCode(com.unboundid.ldap.sdk.ResultCode) Test(org.testng.annotations.Test)

Example 18 with ByteStringBuffer

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));
}
Also used : ByteStringBuffer(com.unboundid.util.ByteStringBuffer) Test(org.testng.annotations.Test)

Example 19 with ByteStringBuffer

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\""));
}
Also used : RDN(com.unboundid.ldap.sdk.RDN) DN(com.unboundid.ldap.sdk.DN) ByteStringBuffer(com.unboundid.util.ByteStringBuffer) Test(org.testng.annotations.Test)

Example 20 with ByteStringBuffer

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("})\""));
}
Also used : ByteStringBuffer(com.unboundid.util.ByteStringBuffer) Test(org.testng.annotations.Test)

Aggregations

ByteStringBuffer (com.unboundid.util.ByteStringBuffer)142 Test (org.testng.annotations.Test)99 NotNull (com.unboundid.util.NotNull)22 DN (com.unboundid.ldap.sdk.DN)20 ByteArrayInputStream (java.io.ByteArrayInputStream)12 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)11 Entry (com.unboundid.ldap.sdk.Entry)10 ResultCode (com.unboundid.ldap.sdk.ResultCode)9 ByteArrayOutputStream (java.io.ByteArrayOutputStream)9 InputStream (java.io.InputStream)8 Modification (com.unboundid.ldap.sdk.Modification)7 File (java.io.File)6 ModifyRequest (com.unboundid.ldap.sdk.ModifyRequest)5 RDN (com.unboundid.ldap.sdk.RDN)5 FileOutputStream (java.io.FileOutputStream)5 Map (java.util.Map)5 Control (com.unboundid.ldap.sdk.Control)4 LDAPException (com.unboundid.ldap.sdk.LDAPException)4 ManageDsaITRequestControl (com.unboundid.ldap.sdk.controls.ManageDsaITRequestControl)4 ArgumentException (com.unboundid.util.args.ArgumentException)4