Search in sources :

Example 36 with ASN1Buffer

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

the class ExtendedRequestProtocolOpTestCase method testExtendedRequestProtocolOpWithOIDWithoutValue.

/**
 * Provides test coverage for the extended request protocol op with an OID but
 * no value.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testExtendedRequestProtocolOpWithOIDWithoutValue() throws Exception {
    ExtendedRequestProtocolOp op = new ExtendedRequestProtocolOp("1.2.3.4", null);
    ASN1Buffer buffer = new ASN1Buffer();
    op.writeTo(buffer);
    byte[] opBytes = buffer.toByteArray();
    ByteArrayInputStream inputStream = new ByteArrayInputStream(opBytes);
    ASN1StreamReader reader = new ASN1StreamReader(inputStream);
    op = new ExtendedRequestProtocolOp(reader);
    op = ExtendedRequestProtocolOp.decodeProtocolOp(op.encodeProtocolOp());
    op = new ExtendedRequestProtocolOp(op.toExtendedRequest());
    assertNotNull(op.getOID());
    assertEquals(op.getOID(), "1.2.3.4");
    assertNull(op.getValue());
    assertEquals(op.getProtocolOpType(), (byte) 0x77);
    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 37 with ASN1Buffer

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

the class ExtendedResponseProtocolOpTestCase method testExtendedResponseProtocolOpSuccess.

/**
 * Provides test coverage for the extended response protocol op for a success
 * response, including OID and value.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testExtendedResponseProtocolOpSuccess() throws Exception {
    ExtendedResponseProtocolOp op = new ExtendedResponseProtocolOp(0, null, null, null, "1.2.3.4", new ASN1OctetString());
    ASN1Buffer buffer = new ASN1Buffer();
    op.writeTo(buffer);
    byte[] opBytes = buffer.toByteArray();
    ByteArrayInputStream inputStream = new ByteArrayInputStream(opBytes);
    ASN1StreamReader reader = new ASN1StreamReader(inputStream);
    op = new ExtendedResponseProtocolOp(reader);
    op = ExtendedResponseProtocolOp.decodeProtocolOp(op.encodeProtocolOp());
    op = new ExtendedResponseProtocolOp(op.toExtendedResult());
    assertEquals(op.getResultCode(), 0);
    assertNull(op.getMatchedDN());
    assertNull(op.getDiagnosticMessage());
    assertNotNull(op.getReferralURLs());
    assertTrue(op.getReferralURLs().isEmpty());
    assertNotNull(op.getResponseOID());
    assertEquals(op.getResponseOID(), "1.2.3.4");
    assertNotNull(op.getResponseValue());
    assertEquals(op.getResponseValue().getValue().length, 0);
    assertEquals(op.getProtocolOpType(), (byte) 0x78);
    assertNotNull(op.toString());
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) ByteArrayInputStream(java.io.ByteArrayInputStream) ASN1Buffer(com.unboundid.asn1.ASN1Buffer) ASN1StreamReader(com.unboundid.asn1.ASN1StreamReader) Test(org.testng.annotations.Test)

Example 38 with ASN1Buffer

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

the class ExtendedResponseProtocolOpTestCase method testReadExtendedResponseInvalidElementType.

/**
 * Tests the behavior when trying to read an extended response with an
 * invalid element type.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test(expectedExceptions = { LDAPException.class })
public void testReadExtendedResponseInvalidElementType() throws Exception {
    ASN1Buffer b = new ASN1Buffer((byte) 0x78);
    ASN1BufferSequence s = b.beginSequence();
    b.addEnumerated(0);
    b.addOctetString();
    b.addOctetString();
    b.addOctetString((byte) 0x80);
    s.end();
    ByteArrayInputStream inputStream = new ByteArrayInputStream(b.toByteArray());
    ASN1StreamReader reader = new ASN1StreamReader(inputStream);
    new ExtendedResponseProtocolOp(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)

Example 39 with ASN1Buffer

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

the class IntermediateResponseProtocolOpTestCase method testReadInvalidElementType.

/**
 * Tests the behavior when trying to read an intermediate response with an
 * invalid element type.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test(expectedExceptions = { LDAPException.class })
public void testReadInvalidElementType() throws Exception {
    ASN1Buffer b = new ASN1Buffer();
    ASN1BufferSequence s = b.beginSequence((byte) 0x79);
    b.addOctetString((byte) 0x99);
    s.end();
    ByteArrayInputStream inputStream = new ByteArrayInputStream(b.toByteArray());
    ASN1StreamReader reader = new ASN1StreamReader(inputStream);
    new IntermediateResponseProtocolOp(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)

Example 40 with ASN1Buffer

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

the class LDAPMessageTestCase method testConstructorNullControlList.

/**
 * Tests the constructor which takes a list of controls with a {@code null}
 * list.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testConstructorNullControlList() throws Exception {
    LinkedList<Control> controlList = null;
    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());
    assertTrue(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) 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