use of com.unboundid.asn1.ASN1Buffer in project ldapsdk by pingidentity.
the class LDAPMessageTestCase method testReadLDAPResponseFromMalformedControl.
/**
* Tests the behavior when trying to read a result containing a malformed
* control.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test(expectedExceptions = { LDAPException.class })
public void testReadLDAPResponseFromMalformedControl() throws Exception {
ASN1Buffer b = new ASN1Buffer();
ASN1BufferSequence msgSequence = b.beginSequence();
b.addInteger(1);
ASN1BufferSequence opSequence = b.beginSequence(LDAPMessage.PROTOCOL_OP_TYPE_ADD_RESPONSE);
b.addEnumerated(0);
b.addOctetString();
b.addOctetString();
opSequence.end();
ASN1BufferSequence controlsSequence = b.beginSequence();
ASN1BufferSequence controlSequence = b.beginSequence();
b.addOctetString("1.2.3.4");
b.addOctetString((byte) 0x01);
controlSequence.end();
controlsSequence.end();
msgSequence.end();
ByteArrayInputStream inputStream = new ByteArrayInputStream(b.toByteArray());
ASN1StreamReader reader = new ASN1StreamReader(inputStream);
LDAPMessage.readLDAPResponseFrom(reader, true);
}
use of com.unboundid.asn1.ASN1Buffer in project ldapsdk by pingidentity.
the class LDAPMessageTestCase method testUnbindRequestMessage.
/**
* Tests the behavior of the {@code LDAPMessage} class with an unbind request
* protocol op.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testUnbindRequestMessage() throws Exception {
UnbindRequestProtocolOp op = new UnbindRequestProtocolOp();
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 UnbindRequestProtocolOp);
assertEquals(m.getProtocolOpType(), LDAPMessage.PROTOCOL_OP_TYPE_UNBIND_REQUEST);
assertNotNull(m.getControls());
assertTrue(m.getControls().isEmpty());
assertNotNull(m.getUnbindRequestProtocolOp());
assertNotNull(m.toString());
}
use of com.unboundid.asn1.ASN1Buffer in project ldapsdk by pingidentity.
the class LDAPMessageTestCase method testConstructorEmptyControlArray.
/**
* Tests the constructor which takes an array of controls with an empty array.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testConstructorEmptyControlArray() throws Exception {
LDAPMessage m = new LDAPMessage(1, new UnbindRequestProtocolOp());
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());
assertTrue(m.getControls().isEmpty());
assertNotNull(m.getUnbindRequestProtocolOp());
assertNotNull(m.toString());
}
use of com.unboundid.asn1.ASN1Buffer in project ldapsdk by pingidentity.
the class LDAPMessageTestCase method testExtendedRequestMessage.
/**
* Tests the behavior of the {@code LDAPMessage} class with an extended
* request protocol op.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testExtendedRequestMessage() throws Exception {
ExtendedRequestProtocolOp op = new ExtendedRequestProtocolOp("1.2.3.4", null);
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 ExtendedRequestProtocolOp);
assertEquals(m.getProtocolOpType(), LDAPMessage.PROTOCOL_OP_TYPE_EXTENDED_REQUEST);
assertNotNull(m.getControls());
assertTrue(m.getControls().isEmpty());
assertNotNull(m.getExtendedRequestProtocolOp());
assertNotNull(m.toString());
}
use of com.unboundid.asn1.ASN1Buffer in project ldapsdk by pingidentity.
the class LDAPMessageTestCase method testIntermediateResponseMessage.
/**
* Tests the behavior of the {@code LDAPMessage} class with an intermediate
* response protocol op.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testIntermediateResponseMessage() throws Exception {
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()));
IntermediateResponseProtocolOp op = new IntermediateResponseProtocolOp("1.2.3.4", new ASN1OctetString());
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 IntermediateResponseProtocolOp);
assertEquals(m.getProtocolOpType(), LDAPMessage.PROTOCOL_OP_TYPE_INTERMEDIATE_RESPONSE);
assertNotNull(m.getControls());
assertFalse(m.getControls().isEmpty());
assertNotNull(m.getIntermediateResponseProtocolOp());
inputStream = new ByteArrayInputStream(b.toByteArray());
reader = new ASN1StreamReader(inputStream);
LDAPResponse r = LDAPMessage.readLDAPResponseFrom(reader, true);
assertNotNull(m.toString());
}
Aggregations