use of org.apache.directory.api.asn1.ber.Asn1Container in project directory-ldap-api by apache.
the class CancelRequestTest method testDecodeCancelBadCancelId.
/**
* Test a Cancel message with a bad cancelId
*/
@Test
public void testDecodeCancelBadCancelId() {
Asn1Decoder cancelDecoder = new CancelDecoder();
ByteBuffer stream = ByteBuffer.allocate(0x08);
stream.put(new byte[] { 0x30, 0x06, 0x02, 0x04, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF }).flip();
// Allocate a Cancel Container
Asn1Container cancelContainer = new CancelContainer();
// Decode a Cancel message
try {
cancelDecoder.decode(stream, cancelContainer);
fail("CancelID expected");
} catch (DecoderException de) {
assertTrue(true);
}
}
use of org.apache.directory.api.asn1.ber.Asn1Container in project directory-ldap-api by apache.
the class CancelRequestTest method testDecodeCancel.
/**
* Test the normal Cancel message
*/
@Test
public void testDecodeCancel() {
Asn1Decoder cancelDecoder = new CancelDecoder();
ByteBuffer stream = ByteBuffer.allocate(0x05);
stream.put(new byte[] { 0x30, 0x03, 0x02, 0x01, 0x01 }).flip();
String decodedPdu = Strings.dumpBytes(stream.array());
// Allocate a Cancel Container
Asn1Container cancelContainer = new CancelContainer();
// Decode a Cancel message
try {
cancelDecoder.decode(stream, cancelContainer);
} catch (DecoderException de) {
de.printStackTrace();
fail(de.getMessage());
}
CancelRequestDecorator cancel = ((CancelContainer) cancelContainer).getCancel();
assertEquals(1, cancel.getCancelId());
// Check the encoding
try {
ByteBuffer bb = cancel.encodeInternal();
String encodedPdu = Strings.dumpBytes(bb.array());
assertEquals(encodedPdu, decodedPdu);
} catch (EncoderException ee) {
ee.printStackTrace();
fail(ee.getMessage());
}
}
use of org.apache.directory.api.asn1.ber.Asn1Container in project directory-ldap-api by apache.
the class CancelRequestTest method testDecodeCancelEmptyCancelId.
/**
* Test a Cancel message with an empty cancelId
*/
@Test
public void testDecodeCancelEmptyCancelId() {
Asn1Decoder cancelDecoder = new CancelDecoder();
ByteBuffer stream = ByteBuffer.allocate(0x04);
stream.put(new byte[] { 0x30, 0x02, 0x02, 0x00 }).flip();
// Allocate a Cancel Container
Asn1Container cancelContainer = new CancelContainer();
// Decode a Cancel message
try {
cancelDecoder.decode(stream, cancelContainer);
fail("CancelID expected");
} catch (DecoderException de) {
assertTrue(true);
}
}
use of org.apache.directory.api.asn1.ber.Asn1Container in project directory-ldap-api by apache.
the class CancelRequestTest method testDecodeCancelMoreThanOneCancelId.
/**
* Test a Cancel message with more than one cancelId
*/
@Test
public void testDecodeCancelMoreThanOneCancelId() {
Asn1Decoder cancelDecoder = new CancelDecoder();
ByteBuffer stream = ByteBuffer.allocate(0x08);
stream.put(new byte[] { 0x30, 0x06, 0x02, 0x01, 0x01, 0x02, 0x01, 0x02 }).flip();
// Allocate a Cancel Container
Asn1Container cancelContainer = new CancelContainer();
// Decode a Cancel message
try {
cancelDecoder.decode(stream, cancelContainer);
fail("CancelID expected");
} catch (DecoderException de) {
assertTrue(true);
}
}
use of org.apache.directory.api.asn1.ber.Asn1Container in project directory-ldap-api by apache.
the class WhoAmIResponseTest method testDecodeWhoAmINoWhoAmIAuthzIdDN.
/**
* Test a WhoAmI message with a DN authzId
*/
@Test
public void testDecodeWhoAmINoWhoAmIAuthzIdDN() {
Asn1Decoder whoAmIResponseDecoder = new WhoAmIResponseDecoder();
ByteBuffer stream = ByteBuffer.allocate(0x0E);
stream.put(new byte[] { 0x04, 0x0C, 'd', 'n', ':', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm' }).flip();
String decodedPdu = Strings.dumpBytes(stream.array());
// Allocate a WhoAmI Container
Asn1Container whoAmIResponseContainer = new WhoAmIResponseContainer();
// Decode a WhoAmI message
try {
whoAmIResponseDecoder.decode(stream, whoAmIResponseContainer);
} catch (DecoderException de) {
fail();
}
WhoAmIResponseDecorator whoAmIResponse = ((WhoAmIResponseContainer) whoAmIResponseContainer).getWhoAmIResponse();
assertNotNull(whoAmIResponse.getAuthzId());
assertEquals("dn:ou=system", Strings.utf8ToString(whoAmIResponse.getAuthzId()));
// Check the encoding
try {
ByteBuffer bb = whoAmIResponse.encodeInternal();
String encodedPdu = Strings.dumpBytes(bb.array());
assertEquals(encodedPdu, decodedPdu);
} catch (EncoderException ee) {
ee.printStackTrace();
fail(ee.getMessage());
}
}
Aggregations