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()));
}
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);
}
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);
}
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()));
}
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);
}
Aggregations