use of com.unboundid.asn1.ASN1StreamReader in project ldapsdk by pingidentity.
the class DeleteResponseProtocolOpTestCase method testReadMalformedDeleteResponse.
/**
* Tests the behavior when trying to read a malformed delete response.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test(expectedExceptions = { LDAPException.class })
public void testReadMalformedDeleteResponse() throws Exception {
byte[] opBytes = { 0x6B, 0x00 };
ByteArrayInputStream inputStream = new ByteArrayInputStream(opBytes);
ASN1StreamReader reader = new ASN1StreamReader(inputStream);
new DeleteResponseProtocolOp(reader);
}
use of com.unboundid.asn1.ASN1StreamReader in project ldapsdk by pingidentity.
the class DeleteResponseProtocolOpTestCase method testDeleteResponseProtocolOpSuccess.
/**
* Provides test coverage for the delete response protocol op for a success
* response.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testDeleteResponseProtocolOpSuccess() throws Exception {
DeleteResponseProtocolOp op = new DeleteResponseProtocolOp(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 DeleteResponseProtocolOp(reader);
op = DeleteResponseProtocolOp.decodeProtocolOp(op.encodeProtocolOp());
op = new DeleteResponseProtocolOp(op.toLDAPResult());
assertEquals(op.getResultCode(), 0);
assertNull(op.getMatchedDN());
assertNull(op.getDiagnosticMessage());
assertNotNull(op.getReferralURLs());
assertTrue(op.getReferralURLs().isEmpty());
assertEquals(op.getProtocolOpType(), (byte) 0x6B);
assertNotNull(op.toString());
}
use of com.unboundid.asn1.ASN1StreamReader in project ldapsdk by pingidentity.
the class ExtendedRequestProtocolOpTestCase method testReadMalformedRequest.
/**
* Tests the behavior when trying to read a malformed extended request.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test(expectedExceptions = { LDAPException.class })
public void testReadMalformedRequest() throws Exception {
byte[] requestBytes = { (byte) 0x77, 0x00 };
ByteArrayInputStream inputStream = new ByteArrayInputStream(requestBytes);
ASN1StreamReader reader = new ASN1StreamReader(inputStream);
new ExtendedRequestProtocolOp(reader);
}
use of com.unboundid.asn1.ASN1StreamReader in project ldapsdk by pingidentity.
the class ExtendedRequestProtocolOpTestCase method testExtendedRequestProtocolOpWithOIDWithValue.
/**
* Provides test coverage for the extended request protocol op with an OID and
* value.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testExtendedRequestProtocolOpWithOIDWithValue() throws Exception {
ExtendedRequestProtocolOp op = new ExtendedRequestProtocolOp("1.2.3.4", new ASN1OctetString());
ASN1Buffer buffer = new ASN1Buffer();
op.writeTo(buffer);
byte[] opBytes = buffer.toByteArray();
ByteArrayInputStream inputStream = new ByteArrayInputStream(opBytes);
ASN1StreamReader reader = new ASN1StreamReader(inputStream);
op = new ExtendedRequestProtocolOp(reader);
op = ExtendedRequestProtocolOp.decodeProtocolOp(op.encodeProtocolOp());
op = new ExtendedRequestProtocolOp(op.toExtendedRequest());
assertNotNull(op.getOID());
assertEquals(op.getOID(), "1.2.3.4");
assertNotNull(op.getValue());
assertEquals(op.getValue().getValue().length, 0);
assertEquals(op.getProtocolOpType(), (byte) 0x77);
assertNotNull(op.toString());
}
use of com.unboundid.asn1.ASN1StreamReader in project ldapsdk by pingidentity.
the class ExtendedResponseProtocolOpTestCase method testExtendedResponseProtocolOpFailure.
/**
* Provides test coverage for the extended response protocol op for a failure
* response with no OID or value.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testExtendedResponseProtocolOpFailure() 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");
ExtendedResponseProtocolOp op = new ExtendedResponseProtocolOp(32, "dc=example,dc=com", "The parent entry did not exist", refs, 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 ExtendedResponseProtocolOp(reader);
op = ExtendedResponseProtocolOp.decodeProtocolOp(op.encodeProtocolOp());
op = new ExtendedResponseProtocolOp(op.toExtendedResult());
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);
assertNull(op.getResponseOID());
assertNull(op.getResponseValue());
assertEquals(op.getProtocolOpType(), (byte) 0x78);
assertNotNull(op.toString());
}
Aggregations