Search in sources :

Example 61 with ASN1OctetString

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

the class IntermediateResponseProtocolOpTestCase method testDecodeInvalidElementType.

/**
 * Tests the behavior when trying to decode an intermediate response with an
 * invalid element type.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test(expectedExceptions = { LDAPException.class })
public void testDecodeInvalidElementType() throws Exception {
    final ASN1Sequence s = new ASN1Sequence(LDAPMessage.PROTOCOL_OP_TYPE_INTERMEDIATE_RESPONSE, new ASN1OctetString((byte) 0x79));
    IntermediateResponseProtocolOp.decodeProtocolOp(s);
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) ASN1Sequence(com.unboundid.asn1.ASN1Sequence) Test(org.testng.annotations.Test)

Example 62 with ASN1OctetString

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

the class LDAPMessageTestCase method testIntermediateResponseMessage.

/**
 * Tests the behavior of the {@code LDAPMessage} class with an intermediate
 * response protocol op.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testIntermediateResponseMessage() throws Exception {
    LinkedList<Control> controls = new LinkedList<Control>();
    controls.add(new Control("1.2.3.4"));
    controls.add(new Control("1.2.3.5", true, new ASN1OctetString()));
    IntermediateResponseProtocolOp op = new IntermediateResponseProtocolOp("1.2.3.4", new ASN1OctetString());
    LDAPMessage m = new LDAPMessage(1, op, controls);
    ASN1Buffer b = new ASN1Buffer();
    m.writeTo(b);
    ByteArrayInputStream inputStream = new ByteArrayInputStream(b.toByteArray());
    ASN1StreamReader reader = new ASN1StreamReader(inputStream);
    m = LDAPMessage.readFrom(reader, true);
    m = LDAPMessage.decode(m.encode());
    assertEquals(m.getMessageID(), 1);
    assertNotNull(m.getProtocolOp());
    assertTrue(m.getProtocolOp() instanceof IntermediateResponseProtocolOp);
    assertEquals(m.getProtocolOpType(), LDAPMessage.PROTOCOL_OP_TYPE_INTERMEDIATE_RESPONSE);
    assertNotNull(m.getControls());
    assertFalse(m.getControls().isEmpty());
    assertNotNull(m.getIntermediateResponseProtocolOp());
    inputStream = new ByteArrayInputStream(b.toByteArray());
    reader = new ASN1StreamReader(inputStream);
    LDAPResponse r = LDAPMessage.readLDAPResponseFrom(reader, true);
    assertNotNull(m.toString());
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) Control(com.unboundid.ldap.sdk.Control) ByteArrayInputStream(java.io.ByteArrayInputStream) ASN1Buffer(com.unboundid.asn1.ASN1Buffer) ASN1StreamReader(com.unboundid.asn1.ASN1StreamReader) LinkedList(java.util.LinkedList) Test(org.testng.annotations.Test)

Example 63 with ASN1OctetString

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

the class AttributeTestCase method testConstructorWithNameSchemaAndOctetStringArrayValues.

/**
 * Tests the constructor which takes a name, a {@code Schema} object, and an
 * array of octet string values.
 * <BR><BR>
 * Access to a Directory Server instance is required for complete processing.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testConstructorWithNameSchemaAndOctetStringArrayValues() throws Exception {
    if (!isDirectoryInstanceAvailable()) {
        return;
    }
    // First, test with a null schema and verify that the case-ignore rule is
    // selected for any attribute.
    ASN1OctetString[] cnValues = { new ASN1OctetString("foo"), new ASN1OctetString("bar") };
    Attribute cnAttr = new Attribute("cn", (Schema) null, cnValues);
    assertNotNull(cnAttr);
    assertNotNull(cnAttr.getName());
    assertEquals(cnAttr.getName(), "cn");
    assertNotNull(cnAttr.getMatchingRule());
    assertEquals(cnAttr.getMatchingRule(), CaseIgnoreStringMatchingRule.getInstance());
    assertTrue(cnAttr.hasValue("foo"));
    ASN1OctetString[] memberValues = { new ASN1OctetString("uid=test.user,ou=People,dc=example,dc=com") };
    Attribute memberAttr = new Attribute("member", (Schema) null, memberValues);
    assertNotNull(memberAttr);
    assertNotNull(memberAttr.getName());
    assertEquals(memberAttr.getName(), "member");
    assertNotNull(memberAttr.getMatchingRule());
    assertEquals(memberAttr.getMatchingRule(), CaseIgnoreStringMatchingRule.getInstance());
    assertFalse(memberAttr.hasValue("uid = test.user, ou=People, dc=example, dc=com"));
    // Next, test with a non-null schema and verify that the case-ignore rule is
    // selected for the cn attribute and .
    cnAttr = new Attribute("cn", schema, cnValues);
    assertNotNull(cnAttr);
    assertNotNull(cnAttr.getName());
    assertEquals(cnAttr.getName(), "cn");
    assertNotNull(cnAttr.getMatchingRule());
    assertEquals(cnAttr.getMatchingRule(), CaseIgnoreStringMatchingRule.getInstance());
    assertTrue(cnAttr.hasValue("foo"));
    memberAttr = new Attribute("member", schema, memberValues);
    assertNotNull(memberAttr);
    assertNotNull(memberAttr.getName());
    assertEquals(memberAttr.getName(), "member");
    assertNotNull(memberAttr.getMatchingRule());
    assertEquals(memberAttr.getMatchingRule(), DistinguishedNameMatchingRule.getInstance());
    assertTrue(memberAttr.hasValue("uid = test.user, ou=People, dc=example, dc=com"));
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) Test(org.testng.annotations.Test)

Example 64 with ASN1OctetString

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

the class BooleanMatchingRuleTestCase method testInvalidValues.

/**
 * Performs a number of tests with invalid values.
 *
 * @param  value  The value to test.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test(dataProvider = "invalidValues", expectedExceptions = { LDAPException.class })
public void testInvalidValues(String value) throws Exception {
    BooleanMatchingRule mr = BooleanMatchingRule.getInstance();
    mr.normalize(new ASN1OctetString(value));
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) Test(org.testng.annotations.Test)

Example 65 with ASN1OctetString

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

the class BooleanMatchingRuleTestCase method testNormalizeSubstring.

/**
 * Ensures that attempts to perform substring normalization will fail.
 *
 * @param  value  The value to test.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test(dataProvider = "trueValues", expectedExceptions = { LDAPException.class })
public void testNormalizeSubstring(String value) throws Exception {
    BooleanMatchingRule mr = BooleanMatchingRule.getInstance();
    mr.normalizeSubstring(new ASN1OctetString(value), (byte) 0x80);
}
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