use of com.unboundid.asn1.ASN1Buffer in project ldapsdk by pingidentity.
the class BindResponseProtocolOpTestCase method testReadBindResponseInvalidElementType.
/**
* Tests the behavior when trying to read a bind response with an invalid
* element type.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test(expectedExceptions = { LDAPException.class })
public void testReadBindResponseInvalidElementType() throws Exception {
ASN1Buffer b = new ASN1Buffer((byte) 0x61);
ASN1BufferSequence s = b.beginSequence();
b.addEnumerated(0);
b.addOctetString();
b.addOctetString();
b.addOctetString((byte) 0x80);
s.end();
ByteArrayInputStream inputStream = new ByteArrayInputStream(b.toByteArray());
ASN1StreamReader reader = new ASN1StreamReader(inputStream);
new BindResponseProtocolOp(reader);
}
use of com.unboundid.asn1.ASN1Buffer in project ldapsdk by pingidentity.
the class LDAPMessageTestCase method testIntermediateResponseMessageNoControls.
/**
* Tests the behavior of the {@code LDAPMessage} class with an intermediate
* response protocol op without any controls.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testIntermediateResponseMessageNoControls() throws Exception {
IntermediateResponseProtocolOp op = new IntermediateResponseProtocolOp("1.2.3.4", new ASN1OctetString());
LDAPMessage m = new LDAPMessage(1, op);
ASN1Buffer b = new ASN1Buffer();
m.writeTo(b);
ByteArrayInputStream inputStream = new ByteArrayInputStream(b.toByteArray());
ASN1StreamReader reader = new ASN1StreamReader(inputStream);
m = LDAPMessage.readFrom(reader, true);
m = LDAPMessage.decode(m.encode());
assertEquals(m.getMessageID(), 1);
assertNotNull(m.getProtocolOp());
assertTrue(m.getProtocolOp() instanceof IntermediateResponseProtocolOp);
assertEquals(m.getProtocolOpType(), LDAPMessage.PROTOCOL_OP_TYPE_INTERMEDIATE_RESPONSE);
assertNotNull(m.getControls());
assertTrue(m.getControls().isEmpty());
assertNotNull(m.getIntermediateResponseProtocolOp());
inputStream = new ByteArrayInputStream(b.toByteArray());
reader = new ASN1StreamReader(inputStream);
LDAPResponse r = LDAPMessage.readLDAPResponseFrom(reader, true);
assertNotNull(m.toString());
}
use of com.unboundid.asn1.ASN1Buffer in project ldapsdk by pingidentity.
the class LDAPMessageTestCase method testConstructorNonEmptyControlArray.
/**
* Tests the constructor which takes an array of controls with a non-empty
* array.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testConstructorNonEmptyControlArray() throws Exception {
LDAPMessage m = new LDAPMessage(1, new UnbindRequestProtocolOp(), new Control("1.2.3.4"), new Control("1.2.3.5"));
ASN1Buffer b = new ASN1Buffer();
m.writeTo(b);
ByteArrayInputStream inputStream = new ByteArrayInputStream(b.toByteArray());
ASN1StreamReader reader = new ASN1StreamReader(inputStream);
m = LDAPMessage.readFrom(reader, true);
m = LDAPMessage.decode(m.encode());
assertEquals(m.getMessageID(), 1);
assertNotNull(m.getProtocolOp());
assertTrue(m.getProtocolOp() instanceof UnbindRequestProtocolOp);
assertNotNull(m.getControls());
assertFalse(m.getControls().isEmpty());
assertNotNull(m.getUnbindRequestProtocolOp());
assertNotNull(m.toString());
}
use of com.unboundid.asn1.ASN1Buffer in project ldapsdk by pingidentity.
the class LDAPMessageTestCase method testCompareResponseMessage.
/**
* Tests the behavior of the {@code LDAPMessage} class with a compare response
* protocol op.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testCompareResponseMessage() 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");
LinkedList<Control> controls = new LinkedList<Control>();
controls.add(new Control("1.2.3.4"));
controls.add(new Control("1.2.3.5", true, new ASN1OctetString()));
CompareResponseProtocolOp op = new CompareResponseProtocolOp(0, null, null, refs);
LDAPMessage m = new LDAPMessage(1, op, controls);
ASN1Buffer b = new ASN1Buffer();
m.writeTo(b);
ByteArrayInputStream inputStream = new ByteArrayInputStream(b.toByteArray());
ASN1StreamReader reader = new ASN1StreamReader(inputStream);
m = LDAPMessage.readFrom(reader, true);
m = LDAPMessage.decode(m.encode());
assertEquals(m.getMessageID(), 1);
assertNotNull(m.getProtocolOp());
assertTrue(m.getProtocolOp() instanceof CompareResponseProtocolOp);
assertEquals(m.getProtocolOpType(), LDAPMessage.PROTOCOL_OP_TYPE_COMPARE_RESPONSE);
assertNotNull(m.getControls());
assertFalse(m.getControls().isEmpty());
assertNotNull(m.getCompareResponseProtocolOp());
inputStream = new ByteArrayInputStream(b.toByteArray());
reader = new ASN1StreamReader(inputStream);
LDAPResponse r = LDAPMessage.readLDAPResponseFrom(reader, true);
assertNotNull(m.toString());
}
use of com.unboundid.asn1.ASN1Buffer in project ldapsdk by pingidentity.
the class LDAPMessageTestCase method testAddResponseMessage.
/**
* Tests the behavior of the {@code LDAPMessage} class with an add response
* protocol op.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testAddResponseMessage() 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");
LinkedList<Control> controls = new LinkedList<Control>();
controls.add(new Control("1.2.3.4"));
controls.add(new Control("1.2.3.5", true, new ASN1OctetString()));
AddResponseProtocolOp op = new AddResponseProtocolOp(0, null, null, refs);
LDAPMessage m = new LDAPMessage(1, op, controls);
ASN1Buffer b = new ASN1Buffer();
m.writeTo(b);
ByteArrayInputStream inputStream = new ByteArrayInputStream(b.toByteArray());
ASN1StreamReader reader = new ASN1StreamReader(inputStream);
m = LDAPMessage.readFrom(reader, true);
m = LDAPMessage.decode(m.encode());
assertEquals(m.getMessageID(), 1);
assertNotNull(m.getProtocolOp());
assertTrue(m.getProtocolOp() instanceof AddResponseProtocolOp);
assertEquals(m.getProtocolOpType(), LDAPMessage.PROTOCOL_OP_TYPE_ADD_RESPONSE);
assertNotNull(m.getControls());
assertFalse(m.getControls().isEmpty());
assertNotNull(m.getAddResponseProtocolOp());
inputStream = new ByteArrayInputStream(b.toByteArray());
reader = new ASN1StreamReader(inputStream);
LDAPResponse r = LDAPMessage.readLDAPResponseFrom(reader, true);
assertNotNull(m.toString());
}
Aggregations