Search in sources :

Example 81 with ASN1Buffer

use of com.unboundid.asn1.ASN1Buffer in project ldapsdk by pingidentity.

the class LDAPMessageTestCase method testSearchDNRequestMessage.

/**
 * Tests the behavior of the {@code LDAPMessage} class with a search request
 * protocol op.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testSearchDNRequestMessage() throws Exception {
    SearchRequestProtocolOp op = new SearchRequestProtocolOp("dc=example,dc=com", SearchScope.SUB, DereferencePolicy.NEVER, 0, 0, false, Filter.createEqualityFilter("uid", "test.user"), null);
    LDAPMessage m = new LDAPMessage(1, op);
    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 SearchRequestProtocolOp);
    assertEquals(m.getProtocolOpType(), LDAPMessage.PROTOCOL_OP_TYPE_SEARCH_REQUEST);
    assertNotNull(m.getControls());
    assertTrue(m.getControls().isEmpty());
    assertNotNull(m.getSearchRequestProtocolOp());
    assertNotNull(m.toString());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ASN1Buffer(com.unboundid.asn1.ASN1Buffer) ASN1StreamReader(com.unboundid.asn1.ASN1StreamReader) Test(org.testng.annotations.Test)

Example 82 with ASN1Buffer

use of com.unboundid.asn1.ASN1Buffer in project ldapsdk by pingidentity.

the class AbandonRequestProtocolOpTestCase method testAbandonRequestProtocolOp.

/**
 * Provides test coverage for the abandon request protocol op.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testAbandonRequestProtocolOp() throws Exception {
    AbandonRequestProtocolOp op = new AbandonRequestProtocolOp(1);
    ASN1Buffer buffer = new ASN1Buffer();
    op.writeTo(buffer);
    byte[] opBytes = buffer.toByteArray();
    ByteArrayInputStream inputStream = new ByteArrayInputStream(opBytes);
    ASN1StreamReader reader = new ASN1StreamReader(inputStream);
    op = new AbandonRequestProtocolOp(reader);
    op = AbandonRequestProtocolOp.decodeProtocolOp(op.encodeProtocolOp());
    assertEquals(op.getIDToAbandon(), 1);
    assertEquals(op.getProtocolOpType(), (byte) 0x50);
    assertNotNull(op.toString());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ASN1Buffer(com.unboundid.asn1.ASN1Buffer) ASN1StreamReader(com.unboundid.asn1.ASN1StreamReader) Test(org.testng.annotations.Test)

Example 83 with ASN1Buffer

use of com.unboundid.asn1.ASN1Buffer in project ldapsdk by pingidentity.

the class AddRequestProtocolOpTestCase method testAddRequestProtocolOp.

/**
 * Provides test coverage for the add request protocol op.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testAddRequestProtocolOp() throws Exception {
    List<Attribute> attrs = new LinkedList<Attribute>();
    attrs.add(new Attribute("objectClass", "top", "domain"));
    attrs.add(new Attribute("dc", "example"));
    AddRequestProtocolOp op = new AddRequestProtocolOp("dc=example,dc=com", attrs);
    ASN1Buffer buffer = new ASN1Buffer();
    op.writeTo(buffer);
    byte[] opBytes = buffer.toByteArray();
    ByteArrayInputStream inputStream = new ByteArrayInputStream(opBytes);
    ASN1StreamReader reader = new ASN1StreamReader(inputStream);
    op = new AddRequestProtocolOp(reader);
    op = AddRequestProtocolOp.decodeProtocolOp(op.encodeProtocolOp());
    op = new AddRequestProtocolOp(op.toAddRequest());
    assertEquals(new DN(op.getDN()), new DN("dc=example,dc=com"));
    attrs = op.getAttributes();
    assertEquals(attrs.size(), 2);
    assertEquals(op.getProtocolOpType(), (byte) 0x68);
    assertNotNull(op.toString());
}
Also used : Attribute(com.unboundid.ldap.sdk.Attribute) ByteArrayInputStream(java.io.ByteArrayInputStream) ASN1Buffer(com.unboundid.asn1.ASN1Buffer) DN(com.unboundid.ldap.sdk.DN) ASN1StreamReader(com.unboundid.asn1.ASN1StreamReader) LinkedList(java.util.LinkedList) Test(org.testng.annotations.Test)

Example 84 with ASN1Buffer

use of com.unboundid.asn1.ASN1Buffer in project ldapsdk by pingidentity.

the class AddResponseProtocolOpTestCase method testAddResponseProtocolOpSuccess.

/**
 * Provides test coverage for the add response protocol op for a success
 * response.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testAddResponseProtocolOpSuccess() throws Exception {
    AddResponseProtocolOp op = new AddResponseProtocolOp(0, null, null, null);
    ASN1Buffer buffer = new ASN1Buffer();
    op.writeTo(buffer);
    byte[] opBytes = buffer.toByteArray();
    ByteArrayInputStream inputStream = new ByteArrayInputStream(opBytes);
    ASN1StreamReader reader = new ASN1StreamReader(inputStream);
    op = new AddResponseProtocolOp(reader);
    op = AddResponseProtocolOp.decodeProtocolOp(op.encodeProtocolOp());
    op = new AddResponseProtocolOp(op.toLDAPResult());
    assertEquals(op.getResultCode(), 0);
    assertNull(op.getMatchedDN());
    assertNull(op.getDiagnosticMessage());
    assertNotNull(op.getReferralURLs());
    assertTrue(op.getReferralURLs().isEmpty());
    assertEquals(op.getProtocolOpType(), (byte) 0x69);
    assertNotNull(op.toString());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ASN1Buffer(com.unboundid.asn1.ASN1Buffer) ASN1StreamReader(com.unboundid.asn1.ASN1StreamReader) Test(org.testng.annotations.Test)

Example 85 with ASN1Buffer

use of com.unboundid.asn1.ASN1Buffer in project ldapsdk by pingidentity.

the class BindRequestProtocolOpTestCase method testReadInvalidCredType.

/**
 * Tests the behavior when attempting to read a bind request protocol op
 * with an invalid type of credentials.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test(expectedExceptions = { LDAPException.class })
public void testReadInvalidCredType() throws Exception {
    ASN1Buffer b = new ASN1Buffer();
    ASN1BufferSequence s = b.beginSequence((byte) 0x60);
    b.addInteger(3);
    b.addOctetString();
    b.addOctetString((byte) 0x0F);
    s.end();
    ByteArrayInputStream inputStream = new ByteArrayInputStream(b.toByteArray());
    ASN1StreamReader reader = new ASN1StreamReader(inputStream);
    new BindRequestProtocolOp(reader);
}
Also used : ASN1BufferSequence(com.unboundid.asn1.ASN1BufferSequence) ByteArrayInputStream(java.io.ByteArrayInputStream) ASN1Buffer(com.unboundid.asn1.ASN1Buffer) ASN1StreamReader(com.unboundid.asn1.ASN1StreamReader) Test(org.testng.annotations.Test)

Aggregations

ASN1Buffer (com.unboundid.asn1.ASN1Buffer)100 ASN1StreamReader (com.unboundid.asn1.ASN1StreamReader)91 ByteArrayInputStream (java.io.ByteArrayInputStream)91 Test (org.testng.annotations.Test)91 ASN1BufferSequence (com.unboundid.asn1.ASN1BufferSequence)47 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)32 LinkedList (java.util.LinkedList)28 DN (com.unboundid.ldap.sdk.DN)21 Control (com.unboundid.ldap.sdk.Control)17 ASN1Element (com.unboundid.asn1.ASN1Element)8 Attribute (com.unboundid.ldap.sdk.Attribute)6 SimpleBindRequest (com.unboundid.ldap.sdk.SimpleBindRequest)4 ASN1BufferSet (com.unboundid.asn1.ASN1BufferSet)3 Modification (com.unboundid.ldap.sdk.Modification)3 RDN (com.unboundid.ldap.sdk.RDN)2 JSONObjectFilter (com.unboundid.ldap.sdk.unboundidds.jsonfilter.JSONObjectFilter)2 OutputStream (java.io.OutputStream)2 ExtendedResponseProtocolOp (com.unboundid.ldap.protocol.ExtendedResponseProtocolOp)1 LDAPMessage (com.unboundid.ldap.protocol.LDAPMessage)1 ExtendedRequest (com.unboundid.ldap.sdk.ExtendedRequest)1