Search in sources :

Example 26 with ASN1Buffer

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

the class BindRequestProtocolOpTestCase method testBindRequestProtocolOpSimpleStringPassword.

/**
 * Provides test coverage for the constructor which takes a string DN and a
 * string password.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testBindRequestProtocolOpSimpleStringPassword() throws Exception {
    BindRequestProtocolOp op = new BindRequestProtocolOp("uid=test.user,ou=People,dc=example,dc=com", "password");
    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 27 with ASN1Buffer

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

the class BindRequestProtocolOpTestCase method testBindRequestProtocolOpSASLNoCredentials.

/**
 * Provides test coverage for the constructor which takes a SASL mechanism
 * and credentials with no credentials.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testBindRequestProtocolOpSASLNoCredentials() throws Exception {
    BindRequestProtocolOp op = new BindRequestProtocolOp("", "EXTERNAL", 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());
    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(), "EXTERNAL");
    assertNull(op.getSASLCredentials());
    assertEquals(op.getProtocolOpType(), (byte) 0x60);
    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 28 with ASN1Buffer

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

the class BindRequestProtocolOpTestCase method testBindRequestProtocolOpGenericSASLMechanism.

/**
 * Provides test coverage for the bind request protocol op when using a
 * generic SASL bind request.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testBindRequestProtocolOpGenericSASLMechanism() throws Exception {
    BindRequestProtocolOp op = new BindRequestProtocolOp("", "TEST", new ASN1OctetString(BindRequestProtocolOp.CRED_TYPE_SASL, "foo"));
    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((GenericSASLBindRequest) op.toBindRequest());
    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(), "TEST");
    assertNotNull(op.getSASLCredentials());
    assertEquals(op.getSASLCredentials().stringValue(), "foo");
    assertEquals(op.getProtocolOpType(), (byte) 0x60);
    assertNotNull(op.toString());
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) ByteArrayInputStream(java.io.ByteArrayInputStream) ASN1Buffer(com.unboundid.asn1.ASN1Buffer) GenericSASLBindRequest(com.unboundid.ldap.sdk.GenericSASLBindRequest) ASN1StreamReader(com.unboundid.asn1.ASN1StreamReader) Test(org.testng.annotations.Test)

Example 29 with ASN1Buffer

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

the class BindResponseProtocolOpTestCase method testBindResponseProtocolOpSuccess.

/**
 * Provides test coverage for the bind response protocol op for a success
 * response, including server SASL credentials.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testBindResponseProtocolOpSuccess() throws Exception {
    BindResponseProtocolOp op = new BindResponseProtocolOp(0, null, null, null, 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 BindResponseProtocolOp(reader);
    op = BindResponseProtocolOp.decodeProtocolOp(op.encodeProtocolOp());
    op = new BindResponseProtocolOp(op.toBindResult());
    assertEquals(op.getResultCode(), 0);
    assertNull(op.getMatchedDN());
    assertNull(op.getDiagnosticMessage());
    assertNotNull(op.getReferralURLs());
    assertTrue(op.getReferralURLs().isEmpty());
    assertNotNull(op.getServerSASLCredentials());
    assertEquals(op.getServerSASLCredentials().getValue().length, 0);
    assertEquals(op.getProtocolOpType(), (byte) 0x61);
    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 30 with ASN1Buffer

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

the class BindResponseProtocolOpTestCase method testBindResponseProtocolOpFailure.

/**
 * Provides test coverage for the bind response protocol op for a failure
 * response with no server SASL credentials.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testBindResponseProtocolOpFailure() 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");
    BindResponseProtocolOp op = new BindResponseProtocolOp(32, "dc=example,dc=com", "The parent entry did not exist", refs, null);
    ASN1Buffer buffer = new ASN1Buffer();
    op.writeTo(buffer);
    byte[] opBytes = buffer.toByteArray();
    ByteArrayInputStream inputStream = new ByteArrayInputStream(opBytes);
    ASN1StreamReader reader = new ASN1StreamReader(inputStream);
    op = new BindResponseProtocolOp(reader);
    op = BindResponseProtocolOp.decodeProtocolOp(op.encodeProtocolOp());
    op = new BindResponseProtocolOp(op.toBindResult());
    assertEquals(op.getResultCode(), 32);
    assertNotNull(op.getMatchedDN());
    assertEquals(new DN(op.getMatchedDN()), new DN("dc=example,dc=com"));
    assertNotNull(op.getDiagnosticMessage());
    assertEquals(op.getDiagnosticMessage(), "The parent entry did not exist");
    assertNotNull(op.getReferralURLs());
    assertFalse(op.getReferralURLs().isEmpty());
    assertEquals(op.getReferralURLs().size(), 2);
    assertNull(op.getServerSASLCredentials());
    assertEquals(op.getProtocolOpType(), (byte) 0x61);
    assertNotNull(op.toString());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ASN1Buffer(com.unboundid.asn1.ASN1Buffer) DN(com.unboundid.ldap.sdk.DN) ASN1OctetString(com.unboundid.asn1.ASN1OctetString) 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