Search in sources :

Example 11 with ASN1StreamReader

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

the class LDAPMessageTestCase method testReadLDAPResponseFromInvalidControlElementType.

/**
 * Tests the behavior when trying to read a result containing a control with
 * an invalid element type.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test(expectedExceptions = { LDAPException.class })
public void testReadLDAPResponseFromInvalidControlElementType() throws Exception {
    ASN1Buffer b = new ASN1Buffer();
    ASN1BufferSequence msgSequence = b.beginSequence();
    b.addInteger(1);
    ASN1BufferSequence opSequence = b.beginSequence(LDAPMessage.PROTOCOL_OP_TYPE_ADD_RESPONSE);
    b.addEnumerated(0);
    b.addOctetString();
    b.addOctetString();
    opSequence.end();
    ASN1BufferSequence controlsSequence = b.beginSequence();
    ASN1BufferSequence controlSequence = b.beginSequence();
    b.addOctetString("1.2.3.4");
    b.addInteger(5);
    controlSequence.end();
    controlsSequence.end();
    msgSequence.end();
    ByteArrayInputStream inputStream = new ByteArrayInputStream(b.toByteArray());
    ASN1StreamReader reader = new ASN1StreamReader(inputStream);
    LDAPMessage.readLDAPResponseFrom(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 12 with ASN1StreamReader

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

the class LDAPMessageTestCase method testReadFromEmptyStream.

/**
 * Tests the {@code LDAPMessage.readFrom} method with an empty stream.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testReadFromEmptyStream() throws Exception {
    ByteArrayInputStream inputStream = new ByteArrayInputStream(new byte[0]);
    ASN1StreamReader reader = new ASN1StreamReader(inputStream);
    assertNull(LDAPMessage.readFrom(reader, true));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ASN1StreamReader(com.unboundid.asn1.ASN1StreamReader) Test(org.testng.annotations.Test)

Example 13 with ASN1StreamReader

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

the class LDAPMessageTestCase method testReadLDAPResponseFromProtocolOpTypeNotResponse.

/**
 * Tests the {@code LDAPMessage.readLDAPResponseFrom} method with a protocol
 * op type that is not a response type.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test(expectedExceptions = { LDAPException.class })
public void testReadLDAPResponseFromProtocolOpTypeNotResponse() throws Exception {
    UnbindRequestProtocolOp op = new UnbindRequestProtocolOp();
    LDAPMessage m = new LDAPMessage(1, op);
    ASN1Buffer b = new ASN1Buffer();
    m.writeTo(b);
    ByteArrayInputStream inputStream = new ByteArrayInputStream(b.toByteArray());
    ASN1StreamReader reader = new ASN1StreamReader(inputStream);
    LDAPMessage.readLDAPResponseFrom(reader, true);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ASN1Buffer(com.unboundid.asn1.ASN1Buffer) ASN1StreamReader(com.unboundid.asn1.ASN1StreamReader) Test(org.testng.annotations.Test)

Example 14 with ASN1StreamReader

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

the class LDAPMessageTestCase method testAbandonRequestMessage.

/**
 * Tests the behavior of the {@code LDAPMessage} class with an abandon request
 * protocol op.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testAbandonRequestMessage() throws Exception {
    AbandonRequestProtocolOp op = new AbandonRequestProtocolOp(1);
    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 AbandonRequestProtocolOp);
    assertEquals(m.getProtocolOpType(), LDAPMessage.PROTOCOL_OP_TYPE_ABANDON_REQUEST);
    assertNotNull(m.getControls());
    assertTrue(m.getControls().isEmpty());
    assertNotNull(m.getAbandonRequestProtocolOp());
    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 15 with ASN1StreamReader

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

the class LDAPMessageTestCase method testBindRequestMessage.

/**
 * Tests the behavior of the {@code LDAPMessage} class with a bind request
 * protocol op.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testBindRequestMessage() throws Exception {
    BindRequestProtocolOp op = new BindRequestProtocolOp("uid=test.user,ou=People,dc=example,dc=com", "password");
    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 BindRequestProtocolOp);
    assertEquals(m.getProtocolOpType(), LDAPMessage.PROTOCOL_OP_TYPE_BIND_REQUEST);
    assertNotNull(m.getControls());
    assertTrue(m.getControls().isEmpty());
    assertNotNull(m.getBindRequestProtocolOp());
    assertNotNull(m.toString());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ASN1Buffer(com.unboundid.asn1.ASN1Buffer) ASN1StreamReader(com.unboundid.asn1.ASN1StreamReader) Test(org.testng.annotations.Test)

Aggregations

ASN1StreamReader (com.unboundid.asn1.ASN1StreamReader)121 ByteArrayInputStream (java.io.ByteArrayInputStream)114 Test (org.testng.annotations.Test)114 ASN1Buffer (com.unboundid.asn1.ASN1Buffer)91 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)31 LinkedList (java.util.LinkedList)28 ASN1BufferSequence (com.unboundid.asn1.ASN1BufferSequence)22 DN (com.unboundid.ldap.sdk.DN)21 Control (com.unboundid.ldap.sdk.Control)18 NotNull (com.unboundid.util.NotNull)13 ASN1StreamReaderSequence (com.unboundid.asn1.ASN1StreamReaderSequence)11 ArrayList (java.util.ArrayList)10 ASN1Exception (com.unboundid.asn1.ASN1Exception)8 IOException (java.io.IOException)8 LDAPException (com.unboundid.ldap.sdk.LDAPException)5 InterruptedIOException (java.io.InterruptedIOException)5 SocketTimeoutException (java.net.SocketTimeoutException)5 Attribute (com.unboundid.ldap.sdk.Attribute)4 SSLSocket (javax.net.ssl.SSLSocket)4 ASN1Element (com.unboundid.asn1.ASN1Element)3