use of com.unboundid.asn1.ASN1StreamReader in project ldapsdk by pingidentity.
the class BindRequestProtocolOpTestCase method testBindRequestProtocolOpGenericSASLMechanism.
/**
* Provides test coverage for the bind request protocol op when using a
* generic SASL bind request.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testBindRequestProtocolOpGenericSASLMechanism() throws Exception {
BindRequestProtocolOp op = new BindRequestProtocolOp("", "TEST", new ASN1OctetString(BindRequestProtocolOp.CRED_TYPE_SASL, "foo"));
ASN1Buffer buffer = new ASN1Buffer();
op.writeTo(buffer);
byte[] opBytes = buffer.toByteArray();
ByteArrayInputStream inputStream = new ByteArrayInputStream(opBytes);
ASN1StreamReader reader = new ASN1StreamReader(inputStream);
op = new BindRequestProtocolOp(reader);
op = BindRequestProtocolOp.decodeProtocolOp(op.encodeProtocolOp());
op = new BindRequestProtocolOp((GenericSASLBindRequest) op.toBindRequest());
assertEquals(op.getVersion(), 3);
assertNotNull(op.getBindDN());
assertEquals(op.getBindDN(), "");
assertEquals(op.getCredentialsType(), BindRequestProtocolOp.CRED_TYPE_SASL);
assertNull(op.getSimplePassword());
assertNotNull(op.getSASLMechanism());
assertEquals(op.getSASLMechanism(), "TEST");
assertNotNull(op.getSASLCredentials());
assertEquals(op.getSASLCredentials().stringValue(), "foo");
assertEquals(op.getProtocolOpType(), (byte) 0x60);
assertNotNull(op.toString());
}
use of com.unboundid.asn1.ASN1StreamReader in project ldapsdk by pingidentity.
the class BindResponseProtocolOpTestCase method testBindResponseProtocolOpSuccess.
/**
* Provides test coverage for the bind response protocol op for a success
* response, including server SASL credentials.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testBindResponseProtocolOpSuccess() throws Exception {
BindResponseProtocolOp op = new BindResponseProtocolOp(0, null, null, null, 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 BindResponseProtocolOp(reader);
op = BindResponseProtocolOp.decodeProtocolOp(op.encodeProtocolOp());
op = new BindResponseProtocolOp(op.toBindResult());
assertEquals(op.getResultCode(), 0);
assertNull(op.getMatchedDN());
assertNull(op.getDiagnosticMessage());
assertNotNull(op.getReferralURLs());
assertTrue(op.getReferralURLs().isEmpty());
assertNotNull(op.getServerSASLCredentials());
assertEquals(op.getServerSASLCredentials().getValue().length, 0);
assertEquals(op.getProtocolOpType(), (byte) 0x61);
assertNotNull(op.toString());
}
use of com.unboundid.asn1.ASN1StreamReader in project ldapsdk by pingidentity.
the class BindResponseProtocolOpTestCase method testBindResponseProtocolOpFailure.
/**
* Provides test coverage for the bind response protocol op for a failure
* response with no server SASL credentials.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testBindResponseProtocolOpFailure() 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");
BindResponseProtocolOp op = new BindResponseProtocolOp(32, "dc=example,dc=com", "The parent entry did not exist", refs, null);
ASN1Buffer buffer = new ASN1Buffer();
op.writeTo(buffer);
byte[] opBytes = buffer.toByteArray();
ByteArrayInputStream inputStream = new ByteArrayInputStream(opBytes);
ASN1StreamReader reader = new ASN1StreamReader(inputStream);
op = new BindResponseProtocolOp(reader);
op = BindResponseProtocolOp.decodeProtocolOp(op.encodeProtocolOp());
op = new BindResponseProtocolOp(op.toBindResult());
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.getServerSASLCredentials());
assertEquals(op.getProtocolOpType(), (byte) 0x61);
assertNotNull(op.toString());
}
use of com.unboundid.asn1.ASN1StreamReader in project ldapsdk by pingidentity.
the class CompareRequestProtocolOpTestCase method testCompareRequestProtocolOp.
/**
* Provides test coverage for the compare request protocol op.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testCompareRequestProtocolOp() throws Exception {
CompareRequestProtocolOp op = new CompareRequestProtocolOp("dc=example,dc=com", "dc", new ASN1OctetString("example"));
ASN1Buffer buffer = new ASN1Buffer();
op.writeTo(buffer);
byte[] opBytes = buffer.toByteArray();
ByteArrayInputStream inputStream = new ByteArrayInputStream(opBytes);
ASN1StreamReader reader = new ASN1StreamReader(inputStream);
op = new CompareRequestProtocolOp(reader);
op = CompareRequestProtocolOp.decodeProtocolOp(op.encodeProtocolOp());
op = new CompareRequestProtocolOp(op.toCompareRequest());
assertEquals(new DN(op.getDN()), new DN("dc=example,dc=com"));
assertNotNull(op.getAttributeName());
assertEquals(op.getAttributeName(), "dc");
assertNotNull(op.getAssertionValue());
assertEquals(op.getAssertionValue().stringValue(), "example");
assertEquals(op.getProtocolOpType(), (byte) 0x6E);
assertNotNull(op.toString());
}
use of com.unboundid.asn1.ASN1StreamReader in project ldapsdk by pingidentity.
the class CompareRequestProtocolOpTestCase method testReadMalformedRequest.
/**
* Tests the behavior when trying to read a malformed compare request.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test(expectedExceptions = { LDAPException.class })
public void testReadMalformedRequest() throws Exception {
byte[] requestBytes = { (byte) 0x6E, 0x00 };
ByteArrayInputStream inputStream = new ByteArrayInputStream(requestBytes);
ASN1StreamReader reader = new ASN1StreamReader(inputStream);
new CompareRequestProtocolOp(reader);
}
Aggregations