Search in sources :

Example 66 with ASN1OctetString

use of com.mindbright.asn1.ASN1OctetString in project ldapsdk by pingidentity.

the class BooleanMatchingRuleTestCase method testMatchesAnyValue.

/**
 * Provides test coverage for the {@code matchesAnyValue} method.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testMatchesAnyValue() throws Exception {
    final BooleanMatchingRule mr = BooleanMatchingRule.getInstance();
    final ASN1OctetString assertionValue = new ASN1OctetString("TRUE");
    assertFalse(mr.matchesAnyValue(assertionValue, null));
    assertFalse(mr.matchesAnyValue(assertionValue, new ASN1OctetString[0]));
    final ASN1OctetString[] attributeValues = { new ASN1OctetString("not a valid Boolean"), new ASN1OctetString("TRUE") };
    assertFalse(mr.matchesAnyValue(null, attributeValues));
    assertTrue(mr.matchesAnyValue(assertionValue, attributeValues));
    assertTrue(mr.matchesAnyValue(new ASN1OctetString("true"), attributeValues));
    assertTrue(mr.matchesAnyValue(new ASN1OctetString("True"), attributeValues));
    assertFalse(mr.matchesAnyValue(new ASN1OctetString("FALSE"), attributeValues));
    try {
        mr.matchesAnyValue(new ASN1OctetString("malformed"), attributeValues);
        fail("Expected an LDAP exception when providing a malformed assertion " + "value");
    } catch (final LDAPException le) {
    // This was expected.
    }
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) LDAPException(com.unboundid.ldap.sdk.LDAPException) Test(org.testng.annotations.Test)

Example 67 with ASN1OctetString

use of com.mindbright.asn1.ASN1OctetString in project ldapsdk by pingidentity.

the class BooleanMatchingRuleTestCase method testTrueValues.

/**
 * Performs a number of tests with values that should resolve to "TRUE".
 *
 * @param  value  The value to test.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test(dataProvider = "trueValues")
public void testTrueValues(String value) throws Exception {
    BooleanMatchingRule mr = BooleanMatchingRule.getInstance();
    assertTrue(mr.valuesMatch(new ASN1OctetString(value), new ASN1OctetString("TRUE")));
    assertEquals(mr.normalize(new ASN1OctetString(value)), new ASN1OctetString("TRUE"));
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) Test(org.testng.annotations.Test)

Example 68 with ASN1OctetString

use of com.mindbright.asn1.ASN1OctetString in project ldapsdk by pingidentity.

the class CaseExactStringMatchingRuleTestCase method testNormalizeSubstring.

/**
 * Tests the {@code normalizeSubstring} method with the provided information.
 *
 * @param  rawValue         The raw value to be normalized.
 * @param  substringType    The substring type to use when performing the
 *                          normalization.
 * @param  normalizedValue  The expected normalized representation of the
 *                          provided value.
 */
@Test(dataProvider = "testNormalizeSubstringValues")
public void testNormalizeSubstring(String rawValue, byte substringType, String normalizedValue) {
    ASN1OctetString rawOS = new ASN1OctetString(rawValue);
    CaseExactStringMatchingRule matchingRule = CaseExactStringMatchingRule.getInstance();
    ASN1OctetString gotOS = matchingRule.normalizeSubstring(rawOS, substringType);
    assertEquals(gotOS.stringValue(), normalizedValue);
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) Test(org.testng.annotations.Test)

Example 69 with ASN1OctetString

use of com.mindbright.asn1.ASN1OctetString in project ldapsdk by pingidentity.

the class IntegerMatchingRuleTestCase method testMatchesSubstring.

/**
 * Tests the {@code matchesSubstring} method to ensure that it throws an
 * exception.
 *
 * @param  valueStr  The string representation of the value.
 * @param  bigInt    The parsed value.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test(dataProvider = "validValues", expectedExceptions = { LDAPException.class })
public void testMatchesSubstring(String valueStr, BigInteger bigInt) throws Exception {
    IntegerMatchingRule mr = IntegerMatchingRule.getInstance();
    mr.matchesSubstring(new ASN1OctetString(valueStr), new ASN1OctetString(valueStr), null, null);
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) Test(org.testng.annotations.Test)

Example 70 with ASN1OctetString

use of com.mindbright.asn1.ASN1OctetString in project ldapsdk by pingidentity.

the class NumericStringMatchingRuleTestCase method testNormalizeSubstring.

/**
 * Tests the {@code normalizeSubstring} method with the provided information.
 *
 * @param  rawValue         The raw value to be normalized.
 * @param  normalizedValue  The expected normalized representation of the
 *                          provided value.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test(dataProvider = "testMatchingValues")
public void testNormalizeSubstring(String rawValue, String normalizedValue) throws Exception {
    ASN1OctetString rawOS = new ASN1OctetString(rawValue);
    NumericStringMatchingRule matchingRule = NumericStringMatchingRule.getInstance();
    assertEquals(matchingRule.normalizeSubstring(rawOS, SUBSTRING_TYPE_SUBINITIAL).stringValue(), normalizedValue);
    assertEquals(matchingRule.normalizeSubstring(rawOS, SUBSTRING_TYPE_SUBANY).stringValue(), normalizedValue);
    assertEquals(matchingRule.normalizeSubstring(rawOS, SUBSTRING_TYPE_SUBFINAL).stringValue(), normalizedValue);
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) Test(org.testng.annotations.Test)

Aggregations

ASN1OctetString (com.unboundid.asn1.ASN1OctetString)1173 Test (org.testng.annotations.Test)852 ASN1Sequence (com.unboundid.asn1.ASN1Sequence)382 Control (com.unboundid.ldap.sdk.Control)310 ASN1Element (com.unboundid.asn1.ASN1Element)237 ArrayList (java.util.ArrayList)204 NotNull (com.unboundid.util.NotNull)191 LDAPException (com.unboundid.ldap.sdk.LDAPException)142 ASN1OctetString (org.bouncycastle.asn1.ASN1OctetString)133 ExtendedResult (com.unboundid.ldap.sdk.ExtendedResult)99 ASN1Enumerated (com.unboundid.asn1.ASN1Enumerated)92 IOException (java.io.IOException)88 ASN1Integer (com.unboundid.asn1.ASN1Integer)80 ExtendedRequest (com.unboundid.ldap.sdk.ExtendedRequest)69 DN (com.unboundid.ldap.sdk.DN)65 LDAPConnection (com.unboundid.ldap.sdk.LDAPConnection)64 ByteArrayInputStream (java.io.ByteArrayInputStream)56 AuthorizationIdentityRequestControl (com.unboundid.ldap.sdk.controls.AuthorizationIdentityRequestControl)53 ASN1Boolean (com.unboundid.asn1.ASN1Boolean)52 AuthorizationIdentityResponseControl (com.unboundid.ldap.sdk.controls.AuthorizationIdentityResponseControl)49