use of com.unboundid.asn1.ASN1Buffer 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());
}
use of com.unboundid.asn1.ASN1Buffer in project ldapsdk by pingidentity.
the class SearchRequestProtocolOpTestCase method testSearchRequestProtocolOpMinimal.
/**
* Provides test coverage for the search request protocol op with a minimal
* set of elements.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testSearchRequestProtocolOpMinimal() throws Exception {
SearchRequestProtocolOp op = new SearchRequestProtocolOp(null, SearchScope.SUB, DereferencePolicy.NEVER, -1, -2, true, Filter.createEqualityFilter("uid", "test.user"), null);
ASN1Buffer buffer = new ASN1Buffer();
op.writeTo(buffer);
byte[] opBytes = buffer.toByteArray();
ByteArrayInputStream inputStream = new ByteArrayInputStream(opBytes);
ASN1StreamReader reader = new ASN1StreamReader(inputStream);
op = new SearchRequestProtocolOp(reader);
op = SearchRequestProtocolOp.decodeProtocolOp(op.encodeProtocolOp());
op = new SearchRequestProtocolOp(op.toSearchRequest());
assertEquals(new DN(op.getBaseDN()), DN.NULL_DN);
assertEquals(op.getScope(), SearchScope.SUB);
assertEquals(op.getDerefPolicy(), DereferencePolicy.NEVER);
assertEquals(op.getSizeLimit(), 0);
assertEquals(op.getTimeLimit(), 0);
assertTrue(op.typesOnly());
assertNotNull(op.getFilter());
assertEquals(op.getFilter(), Filter.create("(uid=test.user)"));
assertNotNull(op.getAttributes());
assertEquals(op.getAttributes().size(), 0);
assertEquals(op.getProtocolOpType(), (byte) 0x63);
assertNotNull(op.toString());
}
use of com.unboundid.asn1.ASN1Buffer in project ldapsdk by pingidentity.
the class SearchResultDoneProtocolOpTestCase method testSearchResultDoneProtocolOpFailure.
/**
* Provides test coverage for the search result done protocol op for a failure
* response.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testSearchResultDoneProtocolOpFailure() 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");
SearchResultDoneProtocolOp op = new SearchResultDoneProtocolOp(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 SearchResultDoneProtocolOp(reader);
op = SearchResultDoneProtocolOp.decodeProtocolOp(op.encodeProtocolOp());
op = new SearchResultDoneProtocolOp(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) 0x65);
assertNotNull(op.toString());
}
use of com.unboundid.asn1.ASN1Buffer in project ldapsdk by pingidentity.
the class SearchResultDoneProtocolOpTestCase method testSearchResultDoneProtocolOpSuccess.
/**
* Provides test coverage for the search result done protocol op for a success
* response.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testSearchResultDoneProtocolOpSuccess() throws Exception {
SearchResultDoneProtocolOp op = new SearchResultDoneProtocolOp(0, null, null, null);
ASN1Buffer buffer = new ASN1Buffer();
op.writeTo(buffer);
byte[] opBytes = buffer.toByteArray();
ByteArrayInputStream inputStream = new ByteArrayInputStream(opBytes);
ASN1StreamReader reader = new ASN1StreamReader(inputStream);
op = new SearchResultDoneProtocolOp(reader);
op = SearchResultDoneProtocolOp.decodeProtocolOp(op.encodeProtocolOp());
op = new SearchResultDoneProtocolOp(op.toLDAPResult());
assertEquals(op.getResultCode(), 0);
assertNull(op.getMatchedDN());
assertNull(op.getDiagnosticMessage());
assertNotNull(op.getReferralURLs());
assertTrue(op.getReferralURLs().isEmpty());
assertEquals(op.getProtocolOpType(), (byte) 0x65);
assertNotNull(op.toString());
}
use of com.unboundid.asn1.ASN1Buffer in project ldapsdk by pingidentity.
the class SearchResultEntryProtocolOpTestCase method testDecodeRequestMalformedAttr.
/**
* Tests the behavior when trying to decode a search result entry with a
* malformed attribute 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) 0x64);
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 SearchResultEntryProtocolOp(reader);
}
Aggregations