Search in sources :

Example 76 with ASN1Buffer

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

the class LDAPMessageTestCase method testReadFromInvalidProtocolOpType.

/**
 * Tests the {@code LDAPMessage.readFrom} method with invalid protocol op
 * type.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test(expectedExceptions = { LDAPException.class })
public void testReadFromInvalidProtocolOpType() throws Exception {
    ASN1Buffer b = new ASN1Buffer();
    ASN1BufferSequence s = b.beginSequence();
    b.addInteger(1);
    b.addOctetString();
    s.end();
    ByteArrayInputStream inputStream = new ByteArrayInputStream(b.toByteArray());
    ASN1StreamReader reader = new ASN1StreamReader(inputStream);
    LDAPMessage.readFrom(reader, true);
}
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)

Example 77 with ASN1Buffer

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

the class LDAPMessageTestCase method testDeleteRequestMessage.

/**
 * Tests the behavior of the {@code LDAPMessage} class with a delete request
 * protocol op.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testDeleteRequestMessage() throws Exception {
    DeleteRequestProtocolOp op = new DeleteRequestProtocolOp("dc=example,dc=com");
    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 DeleteRequestProtocolOp);
    assertEquals(m.getProtocolOpType(), LDAPMessage.PROTOCOL_OP_TYPE_DELETE_REQUEST);
    assertNotNull(m.getControls());
    assertTrue(m.getControls().isEmpty());
    assertNotNull(m.getDeleteRequestProtocolOp());
    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 78 with ASN1Buffer

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

the class LDAPMessageTestCase method testModifyResponseMessage.

/**
 * Tests the behavior of the {@code LDAPMessage} class with a modify response
 * protocol op.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testModifyResponseMessage() 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()));
    ModifyResponseProtocolOp op = new ModifyResponseProtocolOp(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 ModifyResponseProtocolOp);
    assertEquals(m.getProtocolOpType(), LDAPMessage.PROTOCOL_OP_TYPE_MODIFY_RESPONSE);
    assertNotNull(m.getControls());
    assertFalse(m.getControls().isEmpty());
    assertNotNull(m.getModifyResponseProtocolOp());
    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 79 with ASN1Buffer

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

the class LDAPMessageTestCase method testModifyDNResponseMessage.

/**
 * Tests the behavior of the {@code LDAPMessage} class with a modify DN
 * response protocol op.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testModifyDNResponseMessage() 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()));
    ModifyDNResponseProtocolOp op = new ModifyDNResponseProtocolOp(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 ModifyDNResponseProtocolOp);
    assertEquals(m.getProtocolOpType(), LDAPMessage.PROTOCOL_OP_TYPE_MODIFY_DN_RESPONSE);
    assertNotNull(m.getControls());
    assertFalse(m.getControls().isEmpty());
    assertNotNull(m.getModifyDNResponseProtocolOp());
    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 80 with ASN1Buffer

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

the class LDAPMessageTestCase method testConstructorNonEmptyControlList.

/**
 * Tests the constructor which takes a list of controls with a non-empty
 * list.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testConstructorNonEmptyControlList() throws Exception {
    LinkedList<Control> controlList = new LinkedList<Control>();
    controlList.add(new Control("1.2.3.4"));
    controlList.add(new Control("1.2.3.5"));
    LDAPMessage m = new LDAPMessage(1, new UnbindRequestProtocolOp(), controlList);
    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 UnbindRequestProtocolOp);
    assertNotNull(m.getControls());
    assertFalse(m.getControls().isEmpty());
    assertNotNull(m.getUnbindRequestProtocolOp());
    assertNotNull(m.toString());
}
Also used : 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)

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