Search in sources :

Example 66 with ASN1Buffer

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

the class SearchRequestProtocolOpTestCase method testDecodeMalformedFilter.

/**
 * Tests the behavior when trying to decode a search request with a malformed
 * filter.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test(expectedExceptions = { LDAPException.class })
public void testDecodeMalformedFilter() throws Exception {
    ASN1Buffer b = new ASN1Buffer();
    ASN1BufferSequence s = b.beginSequence((byte) 0x63);
    b.addOctetString("dc=example,dc=com");
    b.addEnumerated(2);
    b.addEnumerated(0);
    b.addInteger(0);
    b.addInteger(0);
    b.addBoolean(false);
    b.addOctetString((byte) 0x00);
    b.beginSequence().end();
    s.end();
    ByteArrayInputStream inputStream = new ByteArrayInputStream(b.toByteArray());
    ASN1StreamReader reader = new ASN1StreamReader(inputStream);
    new SearchRequestProtocolOp(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 67 with ASN1Buffer

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

the class UnbindRequestProtocolOpTestCase method testUnbindRequestProtocolOp.

/**
 * Provides test coverage for the unbind request protocol op.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testUnbindRequestProtocolOp() throws Exception {
    UnbindRequestProtocolOp op = new UnbindRequestProtocolOp();
    ASN1Buffer buffer = new ASN1Buffer();
    op.writeTo(buffer);
    byte[] opBytes = buffer.toByteArray();
    ByteArrayInputStream inputStream = new ByteArrayInputStream(opBytes);
    ASN1StreamReader reader = new ASN1StreamReader(inputStream);
    op = new UnbindRequestProtocolOp(reader);
    op = UnbindRequestProtocolOp.decodeProtocolOp(op.encodeProtocolOp());
    assertEquals(op.getProtocolOpType(), (byte) 0x42);
    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 68 with ASN1Buffer

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

the class CompareRequestTestCase method testEncoding.

/**
 * Tests to ensure that the encoding for the provided compare request is
 * identical when using the stream-based and non-stream-based ASN.1 encoding
 * mechanisms.
 *
 * @param  compareRequest  The compare request to be tested.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
private static void testEncoding(final CompareRequest compareRequest) throws Exception {
    ASN1Element protocolOpElement = compareRequest.encodeProtocolOp();
    ASN1Buffer b = new ASN1Buffer();
    compareRequest.writeTo(b);
    assertTrue(Arrays.equals(b.toByteArray(), protocolOpElement.encode()));
}
Also used : ASN1Buffer(com.unboundid.asn1.ASN1Buffer) ASN1Element(com.unboundid.asn1.ASN1Element)

Example 69 with ASN1Buffer

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

the class DeleteRequestTestCase method testEncoding.

/**
 * Tests to ensure that the encoding for the provided delete request is
 * identical when using the stream-based and non-stream-based ASN.1 encoding
 * mechanisms.
 *
 * @param  deleteRequest  The delete request to be tested.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
private static void testEncoding(final DeleteRequest deleteRequest) throws Exception {
    ASN1Element protocolOpElement = deleteRequest.encodeProtocolOp();
    ASN1Buffer b = new ASN1Buffer();
    deleteRequest.writeTo(b);
    assertTrue(Arrays.equals(b.toByteArray(), protocolOpElement.encode()));
}
Also used : ASN1Buffer(com.unboundid.asn1.ASN1Buffer) ASN1Element(com.unboundid.asn1.ASN1Element)

Example 70 with ASN1Buffer

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

the class ModifyDNRequestTestCase method testEncoding.

/**
 * Tests to ensure that the encoding for the provided modify DN request is
 * identical when using the stream-based and non-stream-based ASN.1 encoding
 * mechanisms.
 *
 * @param  modifyDNRequest  The modify DN request to be tested.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
private static void testEncoding(final ModifyDNRequest modifyDNRequest) throws Exception {
    ASN1Element protocolOpElement = modifyDNRequest.encodeProtocolOp();
    ASN1Buffer b = new ASN1Buffer();
    modifyDNRequest.writeTo(b);
    assertTrue(Arrays.equals(b.toByteArray(), protocolOpElement.encode()));
}
Also used : ASN1Buffer(com.unboundid.asn1.ASN1Buffer) ASN1Element(com.unboundid.asn1.ASN1Element)

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