Search in sources :

Example 46 with ASN1Buffer

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

the class SearchRequestTestCase method testEncoding.

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

Example 47 with ASN1Buffer

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

the class SearchResultEntryTestCase method testReadSearchEntryFromMalformedAttribute.

/**
 * Tests the {@code readBindResultFrom} method with an element containing
 * a response sequence with a malformed attribute.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test(expectedExceptions = { LDAPException.class })
public void testReadSearchEntryFromMalformedAttribute() throws Exception {
    ASN1Buffer b = new ASN1Buffer();
    ASN1BufferSequence msgSequence = b.beginSequence();
    b.addInteger(1);
    ASN1BufferSequence opSequence = b.beginSequence(LDAPMessage.PROTOCOL_OP_TYPE_SEARCH_RESULT_ENTRY);
    b.addOctetString("dc=example,dc=com");
    ASN1BufferSequence attrSequence = b.beginSequence();
    b.addEnumerated(1);
    attrSequence.end();
    opSequence.end();
    msgSequence.end();
    ByteArrayInputStream inputStream = new ByteArrayInputStream(b.toByteArray());
    ASN1StreamReader reader = new ASN1StreamReader(inputStream);
    LDAPMessage.readLDAPResponseFrom(reader, true);
}
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 48 with ASN1Buffer

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

the class SearchResultEntryTestCase method testReadSearchEntryFromTooShort.

/**
 * Tests the {@code readSearchEntryFrom} method with an element containing
 * a response sequence that is too short.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test(expectedExceptions = { LDAPException.class })
public void testReadSearchEntryFromTooShort() throws Exception {
    ASN1Buffer b = new ASN1Buffer();
    ASN1BufferSequence msgSequence = b.beginSequence();
    b.addInteger(1);
    ASN1BufferSequence opSequence = b.beginSequence(LDAPMessage.PROTOCOL_OP_TYPE_SEARCH_RESULT_ENTRY);
    b.addOctetString("dc=example,dc=com");
    opSequence.end();
    msgSequence.end();
    ByteArrayInputStream inputStream = new ByteArrayInputStream(b.toByteArray());
    ASN1StreamReader reader = new ASN1StreamReader(inputStream);
    LDAPMessage.readLDAPResponseFrom(reader, true);
}
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 49 with ASN1Buffer

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

the class ModifyRequestTestCase method testEncoding.

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

Example 50 with ASN1Buffer

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

the class FilterTestCase method testReadAndWrite.

/**
 * Tests the {@code readFrom} and {@code writeTo} methods.
 *
 * @param  filter  The string representation of the filter to test.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test(dataProvider = "testValidFilterStrings")
public void testReadAndWrite(final String filter) throws Exception {
    Filter provided = Filter.create(filter);
    ASN1Buffer b = new ASN1Buffer();
    provided.writeTo(b);
    ByteArrayInputStream inputStream = new ByteArrayInputStream(b.toByteArray());
    ASN1StreamReader reader = new ASN1StreamReader(inputStream);
    Filter decoded = Filter.readFrom(reader);
    assertEquals(decoded, provided);
}
Also used : EqualsJSONObjectFilter(com.unboundid.ldap.sdk.unboundidds.jsonfilter.EqualsJSONObjectFilter) JSONObjectFilter(com.unboundid.ldap.sdk.unboundidds.jsonfilter.JSONObjectFilter) 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