Search in sources :

Example 86 with ASN1Buffer

use of com.unboundid.asn1.ASN1Buffer 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 87 with ASN1Buffer

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

Example 88 with ASN1Buffer

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

the class BindRequestProtocolOpTestCase method testBindRequestProtocolOpSimpleBinaryPassword.

/**
 * 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 testBindRequestProtocolOpSimpleBinaryPassword() throws Exception {
    BindRequestProtocolOp op = new BindRequestProtocolOp("uid=test.user,ou=People,dc=example,dc=com", "password".getBytes());
    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()), new DN("uid=test.user,ou=People,dc=example,dc=com"));
    assertEquals(op.getCredentialsType(), BindRequestProtocolOp.CRED_TYPE_SIMPLE);
    assertEquals(op.getSimplePassword().stringValue(), "password");
    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)

Example 89 with ASN1Buffer

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

the class BindRequestProtocolOpTestCase method testBindRequestProtocolOpSimpleStringPasswordAnonymous.

/**
 * Provides test coverage for the constructor which takes a string DN and a
 * string password with an anonymous bind.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testBindRequestProtocolOpSimpleStringPasswordAnonymous() throws Exception {
    BindRequestProtocolOp op = new BindRequestProtocolOp(null, (String) 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)

Example 90 with ASN1Buffer

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

the class BindRequestProtocolOpTestCase method testReadMalformedRequest.

/**
 * Tests the behavior when attempting to read a malformed bind request
 * protocol op.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test(expectedExceptions = { LDAPException.class })
public void testReadMalformedRequest() throws Exception {
    ASN1Buffer b = new ASN1Buffer();
    ASN1BufferSequence s = b.beginSequence((byte) 0x60);
    b.addOctetString();
    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