Search in sources :

Example 21 with ASN1StreamReader

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

the class ModifyDNRequestProtocolOpTestCase method testModifyDNRequestProtocolOpNoNewSuperior.

/**
 * Provides test coverage for the modify DN request protocol op without a new
 * superior DN.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testModifyDNRequestProtocolOpNoNewSuperior() throws Exception {
    ModifyDNRequestProtocolOp op = new ModifyDNRequestProtocolOp("ou=People,dc=example,dc=com", "ou=Users", true, null);
    ASN1Buffer buffer = new ASN1Buffer();
    op.writeTo(buffer);
    byte[] opBytes = buffer.toByteArray();
    ByteArrayInputStream inputStream = new ByteArrayInputStream(opBytes);
    ASN1StreamReader reader = new ASN1StreamReader(inputStream);
    op = new ModifyDNRequestProtocolOp(reader);
    op = ModifyDNRequestProtocolOp.decodeProtocolOp(op.encodeProtocolOp());
    op = new ModifyDNRequestProtocolOp(op.toModifyDNRequest());
    assertEquals(new DN(op.getDN()), new DN("ou=People,dc=example,dc=com"));
    assertNotNull(op.getNewRDN());
    assertEquals(new RDN(op.getNewRDN()), new RDN("ou=Users"));
    assertTrue(op.deleteOldRDN());
    assertNull(op.getNewSuperiorDN());
    assertEquals(op.getProtocolOpType(), (byte) 0x6C);
    assertNotNull(op.toString());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ASN1Buffer(com.unboundid.asn1.ASN1Buffer) RDN(com.unboundid.ldap.sdk.RDN) DN(com.unboundid.ldap.sdk.DN) ASN1StreamReader(com.unboundid.asn1.ASN1StreamReader) RDN(com.unboundid.ldap.sdk.RDN) Test(org.testng.annotations.Test)

Example 22 with ASN1StreamReader

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

the class ModifyDNResponseProtocolOpTestCase method testModifyDNResponseProtocolOpFailure.

/**
 * Provides test coverage for the modify DN response protocol op for a failure
 * response.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testModifyDNResponseProtocolOpFailure() 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");
    ModifyDNResponseProtocolOp op = new ModifyDNResponseProtocolOp(32, "dc=example,dc=com", "The parent entry did not exist", refs);
    ASN1Buffer buffer = new ASN1Buffer();
    op.writeTo(buffer);
    byte[] opBytes = buffer.toByteArray();
    ByteArrayInputStream inputStream = new ByteArrayInputStream(opBytes);
    ASN1StreamReader reader = new ASN1StreamReader(inputStream);
    op = new ModifyDNResponseProtocolOp(reader);
    op = ModifyDNResponseProtocolOp.decodeProtocolOp(op.encodeProtocolOp());
    op = new ModifyDNResponseProtocolOp(op.toLDAPResult());
    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);
    assertEquals(op.getProtocolOpType(), (byte) 0x6D);
    assertNotNull(op.toString());
}
Also used : 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 23 with ASN1StreamReader

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

the class ModifyRequestProtocolOpTestCase method testDecodeRequestMalformedAttr.

/**
 * Tests the behavior when trying to decode a modify request with a malformed
 * modification list.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test(expectedExceptions = { LDAPException.class })
public void testDecodeRequestMalformedAttr() throws Exception {
    ASN1Buffer b = new ASN1Buffer();
    ASN1BufferSequence opSequence = b.beginSequence((byte) 0x66);
    b.addOctetString("dc=example,dc=com");
    ASN1BufferSequence attrsSequence = b.beginSequence();
    b.addOctetString();
    attrsSequence.end();
    opSequence.end();
    byte[] requestBytes = b.toByteArray();
    ByteArrayInputStream inputStream = new ByteArrayInputStream(requestBytes);
    ASN1StreamReader reader = new ASN1StreamReader(inputStream);
    new ModifyRequestProtocolOp(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 24 with ASN1StreamReader

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

the class ModifyResponseProtocolOpTestCase method testReadMalformedModifyResponse.

/**
 * Tests the behavior when trying to read a malformed modify response.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test(expectedExceptions = { LDAPException.class })
public void testReadMalformedModifyResponse() throws Exception {
    byte[] opBytes = { 0x67, 0x00 };
    ByteArrayInputStream inputStream = new ByteArrayInputStream(opBytes);
    ASN1StreamReader reader = new ASN1StreamReader(inputStream);
    new ModifyResponseProtocolOp(reader);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ASN1StreamReader(com.unboundid.asn1.ASN1StreamReader) Test(org.testng.annotations.Test)

Example 25 with ASN1StreamReader

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

the class ModifyResponseProtocolOpTestCase method testModifyResponseProtocolOpFailure.

/**
 * Provides test coverage for the modify response protocol op for a failure
 * response.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testModifyResponseProtocolOpFailure() 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");
    ModifyResponseProtocolOp op = new ModifyResponseProtocolOp(32, "dc=example,dc=com", "The parent entry did not exist", refs);
    ASN1Buffer buffer = new ASN1Buffer();
    op.writeTo(buffer);
    byte[] opBytes = buffer.toByteArray();
    ByteArrayInputStream inputStream = new ByteArrayInputStream(opBytes);
    ASN1StreamReader reader = new ASN1StreamReader(inputStream);
    op = new ModifyResponseProtocolOp(reader);
    op = ModifyResponseProtocolOp.decodeProtocolOp(op.encodeProtocolOp());
    op = new ModifyResponseProtocolOp(op.toLDAPResult());
    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);
    assertEquals(op.getProtocolOpType(), (byte) 0x67);
    assertNotNull(op.toString());
}
Also used : 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)

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