Search in sources :

Example 96 with ASN1StreamReader

use of com.unboundid.asn1.ASN1StreamReader 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 97 with ASN1StreamReader

use of com.unboundid.asn1.ASN1StreamReader 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 98 with ASN1StreamReader

use of com.unboundid.asn1.ASN1StreamReader 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)

Example 99 with ASN1StreamReader

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

the class BindRequestProtocolOpTestCase method testBindRequestProtocolOpSASLWithCredentials.

/**
 * Provides test coverage for the constructor which takes a SASL mechanism
 * and credentials.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testBindRequestProtocolOpSASLWithCredentials() throws Exception {
    BindRequestProtocolOp op = new BindRequestProtocolOp(null, "PLAIN", new ASN1OctetString("\u0000u:test.user\u00000password"));
    ASN1Buffer buffer = new ASN1Buffer();
    op.writeTo(buffer);
    byte[] opBytes = buffer.toByteArray();
    ByteArrayInputStream inputStream = new ByteArrayInputStream(opBytes);
    ASN1StreamReader reader = new ASN1StreamReader(inputStream);
    op = new BindRequestProtocolOp(reader);
    op = BindRequestProtocolOp.decodeProtocolOp(op.encodeProtocolOp());
    assertEquals(op.getVersion(), 3);
    assertNotNull(op.getBindDN());
    assertEquals(op.getBindDN(), "");
    assertEquals(op.getCredentialsType(), BindRequestProtocolOp.CRED_TYPE_SASL);
    assertNull(op.getSimplePassword());
    assertNotNull(op.getSASLMechanism());
    assertEquals(op.getSASLMechanism(), "PLAIN");
    assertNotNull(op.getSASLCredentials());
    assertEquals(op.getProtocolOpType(), (byte) 0x60);
    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 100 with ASN1StreamReader

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

the class BindRequestProtocolOpTestCase method testBindRequestProtocolOpSimpleBinaryPasswordAnonymous.

/**
 * Provides test coverage for the constructor which takes a string DN and a
 * binary password.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testBindRequestProtocolOpSimpleBinaryPasswordAnonymous() throws Exception {
    BindRequestProtocolOp op = new BindRequestProtocolOp(null, (byte[]) null);
    ASN1Buffer buffer = new ASN1Buffer();
    op.writeTo(buffer);
    byte[] opBytes = buffer.toByteArray();
    ByteArrayInputStream inputStream = new ByteArrayInputStream(opBytes);
    ASN1StreamReader reader = new ASN1StreamReader(inputStream);
    op = new BindRequestProtocolOp(reader);
    op = BindRequestProtocolOp.decodeProtocolOp(op.encodeProtocolOp());
    op = new BindRequestProtocolOp((SimpleBindRequest) op.toBindRequest());
    assertEquals(op.getVersion(), 3);
    assertEquals(new DN(op.getBindDN()), DN.NULL_DN);
    assertEquals(op.getCredentialsType(), BindRequestProtocolOp.CRED_TYPE_SIMPLE);
    assertEquals(op.getSimplePassword().stringValue(), "");
    assertNull(op.getSASLMechanism());
    assertNull(op.getSASLCredentials());
    assertEquals(op.getProtocolOpType(), (byte) 0x60);
    assertNotNull(op.toString());
}
Also used : SimpleBindRequest(com.unboundid.ldap.sdk.SimpleBindRequest) ByteArrayInputStream(java.io.ByteArrayInputStream) ASN1Buffer(com.unboundid.asn1.ASN1Buffer) DN(com.unboundid.ldap.sdk.DN) 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