Search in sources :

Example 31 with ASN1StreamReader

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

the class SearchResultEntryProtocolOpTestCase method testDecodeMalformedRequest.

/**
 * Tests the behavior when trying to decode a malformed search result entry.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test(expectedExceptions = { LDAPException.class })
public void testDecodeMalformedRequest() throws Exception {
    byte[] requestBytes = { (byte) 0x64, 0x00 };
    ByteArrayInputStream inputStream = new ByteArrayInputStream(requestBytes);
    ASN1StreamReader reader = new ASN1StreamReader(inputStream);
    new SearchResultEntryProtocolOp(reader);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ASN1StreamReader(com.unboundid.asn1.ASN1StreamReader) Test(org.testng.annotations.Test)

Example 32 with ASN1StreamReader

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

the class SearchResultEntryProtocolOpTestCase method testSearchResultEntryProtocolOp.

/**
 * Provides test coverage for the search result entry protocol op.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testSearchResultEntryProtocolOp() throws Exception {
    List<Attribute> attrs = new LinkedList<Attribute>();
    attrs.add(new Attribute("objectClass", "top", "domain"));
    attrs.add(new Attribute("dc", "example"));
    SearchResultEntryProtocolOp op = new SearchResultEntryProtocolOp("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 SearchResultEntryProtocolOp(reader);
    op = SearchResultEntryProtocolOp.decodeProtocolOp(op.encodeProtocolOp());
    op = new SearchResultEntryProtocolOp(op.toSearchResultEntry());
    assertEquals(new DN(op.getDN()), new DN("dc=example,dc=com"));
    attrs = op.getAttributes();
    assertEquals(attrs.size(), 2);
    assertEquals(op.getProtocolOpType(), (byte) 0x64);
    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 33 with ASN1StreamReader

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

the class SearchResultReferenceProtocolOpTestCase method testSearchResultReferenceProtocolOp.

/**
 * Provides test coverage for the search result reference protocol op.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testSearchResultReferenceProtocolOp() 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");
    SearchResultReferenceProtocolOp op = new SearchResultReferenceProtocolOp(refs);
    ASN1Buffer buffer = new ASN1Buffer();
    op.writeTo(buffer);
    byte[] opBytes = buffer.toByteArray();
    ByteArrayInputStream inputStream = new ByteArrayInputStream(opBytes);
    ASN1StreamReader reader = new ASN1StreamReader(inputStream);
    op = new SearchResultReferenceProtocolOp(reader);
    op = SearchResultReferenceProtocolOp.decodeProtocolOp(op.encodeProtocolOp());
    op = new SearchResultReferenceProtocolOp(op.toSearchResultReference());
    assertNotNull(op.getReferralURLs());
    assertEquals(op.getReferralURLs().size(), 2);
    assertEquals(op.getProtocolOpType(), (byte) 0x73);
    assertNotNull(op.toString());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ASN1Buffer(com.unboundid.asn1.ASN1Buffer) ASN1OctetString(com.unboundid.asn1.ASN1OctetString) ASN1StreamReader(com.unboundid.asn1.ASN1StreamReader) LinkedList(java.util.LinkedList) Test(org.testng.annotations.Test)

Example 34 with ASN1StreamReader

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

the class UnbindRequestProtocolOpTestCase method testReadMalformedRequest.

/**
 * Tests the behavior when trying to read a malformed unbind request.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test(expectedExceptions = { LDAPException.class })
public void testReadMalformedRequest() throws Exception {
    byte[] requestBytes = { (byte) 0x42 };
    ByteArrayInputStream inputStream = new ByteArrayInputStream(requestBytes);
    ASN1StreamReader reader = new ASN1StreamReader(inputStream);
    new UnbindRequestProtocolOp(reader);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ASN1StreamReader(com.unboundid.asn1.ASN1StreamReader) Test(org.testng.annotations.Test)

Example 35 with ASN1StreamReader

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

the class AbandonRequestProtocolOpTestCase method testReadMalformedRequest.

/**
 * Tests the behavior when trying to read a malformed abandon request.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test(expectedExceptions = { LDAPException.class })
public void testReadMalformedRequest() throws Exception {
    byte[] requestBytes = { (byte) 0x50, 0x00 };
    ByteArrayInputStream inputStream = new ByteArrayInputStream(requestBytes);
    ASN1StreamReader reader = new ASN1StreamReader(inputStream);
    new AbandonRequestProtocolOp(reader);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) 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