use of com.unboundid.asn1.ASN1StreamReader in project ldapsdk by pingidentity.
the class AddRequestProtocolOpTestCase method testDecodeRequestMalformedAttr.
/**
* Tests the behavior when trying to decode an add request 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) 0x68);
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 AddRequestProtocolOp(reader);
}
use of com.unboundid.asn1.ASN1StreamReader in project ldapsdk by pingidentity.
the class AddResponseProtocolOpTestCase method testAddResponseProtocolOpFailure.
/**
* Provides test coverage for the add response protocol op for a failure
* response.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testAddResponseProtocolOpFailure() 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");
AddResponseProtocolOp op = new AddResponseProtocolOp(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 AddResponseProtocolOp(reader);
op = AddResponseProtocolOp.decodeProtocolOp(op.encodeProtocolOp());
op = new AddResponseProtocolOp(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) 0x69);
assertNotNull(op.toString());
}
use of com.unboundid.asn1.ASN1StreamReader in project ldapsdk by pingidentity.
the class AddResponseProtocolOpTestCase method testReadMalformedAddResponse.
/**
* Tests the behavior when trying to read a malformed add response.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test(expectedExceptions = { LDAPException.class })
public void testReadMalformedAddResponse() throws Exception {
byte[] opBytes = { 0x69, 0x00 };
ByteArrayInputStream inputStream = new ByteArrayInputStream(opBytes);
ASN1StreamReader reader = new ASN1StreamReader(inputStream);
new AddResponseProtocolOp(reader);
}
use of com.unboundid.asn1.ASN1StreamReader in project ldapsdk by pingidentity.
the class BindRequestProtocolOpTestCase method testBindRequestProtocolOpSimpleStringPassword.
/**
* Provides test coverage for the constructor which takes a string DN and a
* string password.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testBindRequestProtocolOpSimpleStringPassword() throws Exception {
BindRequestProtocolOp op = new BindRequestProtocolOp("uid=test.user,ou=People,dc=example,dc=com", "password");
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((SimpleBindRequest) op.toBindRequest());
assertEquals(op.getVersion(), 3);
assertEquals(new DN(op.getBindDN()), new DN("uid=test.user,ou=People,dc=example,dc=com"));
assertEquals(op.getCredentialsType(), BindRequestProtocolOp.CRED_TYPE_SIMPLE);
assertEquals(op.getSimplePassword().stringValue(), "password");
assertNull(op.getSASLMechanism());
assertNull(op.getSASLCredentials());
assertEquals(op.getProtocolOpType(), (byte) 0x60);
assertNotNull(op.toString());
}
use of com.unboundid.asn1.ASN1StreamReader in project ldapsdk by pingidentity.
the class BindRequestProtocolOpTestCase method testBindRequestProtocolOpSASLNoCredentials.
/**
* Provides test coverage for the constructor which takes a SASL mechanism
* and credentials with no credentials.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testBindRequestProtocolOpSASLNoCredentials() throws Exception {
BindRequestProtocolOp op = new BindRequestProtocolOp("", "EXTERNAL", null);
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());
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(), "EXTERNAL");
assertNull(op.getSASLCredentials());
assertEquals(op.getProtocolOpType(), (byte) 0x60);
assertNotNull(op.toString());
}
Aggregations