Search in sources :

Example 36 with ASN1OctetString

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

the class LDAPMessageTestCase method testSearchResultDoneMessage.

/**
 * Tests the behavior of the {@code LDAPMessage} class with a search result
 * done protocol op.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testSearchResultDoneMessage() throws Exception {
    LinkedList<String> refs = new LinkedList<String>();
    refs.add("ldap://server1.example.com:389/dc=example,dc=com");
    refs.add("ldap://server2.example.com:389/dc=example,dc=com");
    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()));
    SearchResultDoneProtocolOp op = new SearchResultDoneProtocolOp(0, null, null, refs);
    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 SearchResultDoneProtocolOp);
    assertEquals(m.getProtocolOpType(), LDAPMessage.PROTOCOL_OP_TYPE_SEARCH_RESULT_DONE);
    assertNotNull(m.getControls());
    assertFalse(m.getControls().isEmpty());
    assertNotNull(m.getSearchResultDoneProtocolOp());
    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) ASN1OctetString(com.unboundid.asn1.ASN1OctetString) ASN1StreamReader(com.unboundid.asn1.ASN1StreamReader) LinkedList(java.util.LinkedList) Test(org.testng.annotations.Test)

Example 37 with ASN1OctetString

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

the class LDAPMessageTestCase method testSearchResultReferenceMessage.

/**
 * Tests the behavior of the {@code LDAPMessage} class with a search result
 * reference protocol op.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testSearchResultReferenceMessage() 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()));
    LinkedList<String> refs = new LinkedList<String>();
    refs.add("ldap://server1.example.com:389/dc=example,dc=com");
    refs.add("ldap://server2.example.com:389/dc=example,dc=com");
    SearchResultReferenceProtocolOp op = new SearchResultReferenceProtocolOp(refs);
    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 SearchResultReferenceProtocolOp);
    assertEquals(m.getProtocolOpType(), LDAPMessage.PROTOCOL_OP_TYPE_SEARCH_RESULT_REFERENCE);
    assertNotNull(m.getControls());
    assertFalse(m.getControls().isEmpty());
    assertNotNull(m.getSearchResultReferenceProtocolOp());
    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) ASN1OctetString(com.unboundid.asn1.ASN1OctetString) ASN1StreamReader(com.unboundid.asn1.ASN1StreamReader) LinkedList(java.util.LinkedList) Test(org.testng.annotations.Test)

Example 38 with ASN1OctetString

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

the class LDAPMessageTestCase method testExtendedResponseMessage.

/**
 * Tests the behavior of the {@code LDAPMessage} class with an extended
 * response protocol op.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testExtendedResponseMessage() throws Exception {
    LinkedList<String> refs = new LinkedList<String>();
    refs.add("ldap://server1.example.com:389/dc=example,dc=com");
    refs.add("ldap://server2.example.com:389/dc=example,dc=com");
    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()));
    ExtendedResponseProtocolOp op = new ExtendedResponseProtocolOp(0, null, null, refs, "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 ExtendedResponseProtocolOp);
    assertEquals(m.getProtocolOpType(), LDAPMessage.PROTOCOL_OP_TYPE_EXTENDED_RESPONSE);
    assertNotNull(m.getControls());
    assertFalse(m.getControls().isEmpty());
    assertNotNull(m.getExtendedResponseProtocolOp());
    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) ASN1OctetString(com.unboundid.asn1.ASN1OctetString) ASN1StreamReader(com.unboundid.asn1.ASN1StreamReader) LinkedList(java.util.LinkedList) Test(org.testng.annotations.Test)

Example 39 with ASN1OctetString

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

the class LDAPMessageTestCase method testDeleteResponseMessage.

/**
 * Tests the behavior of the {@code LDAPMessage} class with a delete response
 * protocol op.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testDeleteResponseMessage() throws Exception {
    LinkedList<String> refs = new LinkedList<String>();
    refs.add("ldap://server1.example.com:389/dc=example,dc=com");
    refs.add("ldap://server2.example.com:389/dc=example,dc=com");
    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()));
    DeleteResponseProtocolOp op = new DeleteResponseProtocolOp(0, null, null, refs);
    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 DeleteResponseProtocolOp);
    assertEquals(m.getProtocolOpType(), LDAPMessage.PROTOCOL_OP_TYPE_DELETE_RESPONSE);
    assertNotNull(m.getControls());
    assertFalse(m.getControls().isEmpty());
    assertNotNull(m.getDeleteResponseProtocolOp());
    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) ASN1OctetString(com.unboundid.asn1.ASN1OctetString) ASN1StreamReader(com.unboundid.asn1.ASN1StreamReader) LinkedList(java.util.LinkedList) Test(org.testng.annotations.Test)

Example 40 with ASN1OctetString

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

the class CaseExactStringMatchingRuleTestCase method testNonMatchingValues.

/**
 * Tests the case exact string matching rule with a number of value pairs
 * that should not be considered matches.
 *
 * @param  value1  The first value to compare.
 * @param  value2  The second value to compare.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test(dataProvider = "testNonMatchingValues")
public void testNonMatchingValues(String value1, String value2) throws Exception {
    ASN1OctetString value1OS = new ASN1OctetString(value1);
    ASN1OctetString value2OS = new ASN1OctetString(value2);
    CaseExactStringMatchingRule matchingRule = CaseExactStringMatchingRule.getInstance();
    assertFalse(matchingRule.valuesMatch(value1OS, value2OS));
}
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