use of org.apache.directory.api.asn1.ber.Asn1Container in project directory-ldap-api by apache.
the class LdapDecoderTest method testDecodeBadTagTransition.
/**
* Test the decoding of a PDU with a bad primitive Length. The second TLV
* has a length of 0x02 when the PDU is 0x01 bytes long.
*/
@Test
public void testDecodeBadTagTransition() {
Asn1Decoder ldapDecoder = new Asn1Decoder();
ByteBuffer stream = ByteBuffer.allocate(0x35);
stream.put(new byte[] { 0x30, // LDAPMessage ::=SEQUENCE {
0x33, // Length should be 0x01...
0x02, 0x01, // messageID MessageID
0x01, 0x2D, // CHOICE { ..., bindRequest BindRequest, ...
0x2D, // BindRequest ::= APPLICATION[0] SEQUENCE {
0x02, 0x01, // version INTEGER (1..127),
0x03, 0x04, // name LDAPDN,
0x1F, 'u', 'i', 'd', '=', 'a', 'k', 'a', 'r', 'a', 's', 'u', 'l', 'u', ',', 'd', 'c', '=', 'e', 'x', 'a', 'm', 'p', 'l', 'e', ',', 'd', 'c', '=', 'c', 'o', 'm', (byte) 0x80, // authentication
0x08, // ...
'p', 'a', 's', 's', 'w', 'o', 'r', 'd' });
stream.flip();
// Allocate a LdapMessage Container
Asn1Container ldapMessageContainer = new LdapMessageContainer<MessageDecorator<? extends Message>>(codec);
// Decode a BindRequest PDU
try {
ldapDecoder.decode(stream, ldapMessageContainer);
} catch (DecoderException de) {
assertEquals("ERR_01200_BAD_TRANSITION_FROM_STATE Bad transition from state MESSAGE_ID_STATE, tag 0x2D", de.getMessage());
return;
}
fail("Should never reach this point.");
}
use of org.apache.directory.api.asn1.ber.Asn1Container in project directory-ldap-api by apache.
the class LdapDecoderTest method testDecodeBadPrimitiveLengthTooBig.
/**
* Test the decoding of a PDU with a bad primitive Length. The second TLV
* has a length of 0x02 when the PDU is 0x01 bytes long.
*/
@Test
public void testDecodeBadPrimitiveLengthTooBig() {
Asn1Decoder ldapDecoder = new Asn1Decoder();
ByteBuffer stream = ByteBuffer.allocate(0x35);
stream.put(new byte[] { 0x30, // LDAPMessage ::=SEQUENCE {
0x33, // Length should be 0x01...
0x02, 0x02, // messageID MessageID
0x01, 0x60, // CHOICE { ..., bindRequest BindRequest, ...
0x2E, // BindRequest ::= APPLICATION[0] SEQUENCE {
0x02, 0x01, // version INTEGER (1..127),
0x03, 0x04, // name LDAPDN,
0x1F, 'u', 'i', 'd', '=', 'a', 'k', 'a', 'r', 'a', 's', 'u', 'l', 'u', ',', 'd', 'c', '=', 'e', 'x', 'a', 'm', 'p', 'l', 'e', ',', 'd', 'c', '=', 'c', 'o', 'm', (byte) 0x80, // authentication AuthenticationChoice
0x08, // ...
'p', 'a', 's', 's', 'w', 'o', 'r' });
stream.flip();
// Allocate a LdapMessage Container
Asn1Container ldapMessageContainer = new LdapMessageContainer<MessageDecorator<? extends Message>>(codec);
// Decode a BindRequest PDU
try {
ldapDecoder.decode(stream, ldapMessageContainer);
} catch (DecoderException de) {
assertEquals("ERR_01200_BAD_TRANSITION_FROM_STATE Bad transition from state MESSAGE_ID_STATE, tag 0x2E", de.getMessage());
return;
}
fail("Should never reach this point.");
}
use of org.apache.directory.api.asn1.ber.Asn1Container in project directory-ldap-api by apache.
the class LdapMessageTest method testDecodeMessageIdMaxInt.
/**
* Test the decoding of messageId which value is -1
*/
@Test
public void testDecodeMessageIdMaxInt() {
Asn1Decoder ldapDecoder = new Asn1Decoder();
ByteBuffer stream = ByteBuffer.allocate(0x08);
stream.put(new byte[] { // LDAPMessage ::=SEQUENCE {
0x30, // LDAPMessage ::=SEQUENCE {
0x06, // messageID MessageID = -1
0x02, 0x04, (byte) 0x7f, (byte) 0xff, (byte) 0xff, (byte) 0xff });
stream.flip();
// Allocate a LdapMessage Container
Asn1Container ldapMessageContainer = new LdapMessageContainer<MessageDecorator<? extends Message>>(codec);
// Decode a BindRequest PDU
try {
ldapDecoder.decode(stream, ldapMessageContainer);
} catch (DecoderException de) {
assertTrue(true);
return;
}
fail("We should not reach this point !");
}
use of org.apache.directory.api.asn1.ber.Asn1Container in project directory-ldap-api by apache.
the class LdapMessageTest method testDecodeWrongProtocolOpMaxInt.
/**
* Test the decoding of a message with a wrong protocol operation
*/
@Test
public void testDecodeWrongProtocolOpMaxInt() {
byte[] buffer = new byte[] { // LDAPMessage ::=SEQUENCE {
0x30, // LDAPMessage ::=SEQUENCE {
0x05, 0x02, 0x01, // messageID MessageID = 1
0x01, 0x42, // ProtocolOp
0x00 };
Asn1Decoder ldapDecoder = new Asn1Decoder();
ByteBuffer stream = ByteBuffer.allocate(0x07);
for (int i = 0; i < 256; i++) {
buffer[5] = (byte) i;
stream.put(buffer);
stream.flip();
// Allocate a LdapMessage Container
Asn1Container ldapMessageContainer = new LdapMessageContainer<MessageDecorator<? extends Message>>(codec);
// Decode a BindRequest PDU
try {
ldapDecoder.decode(stream, ldapMessageContainer);
} catch (DecoderException de) {
switch(i) {
case 0x42:
case 0x4A:
// AbandonRequest
case 0x50:
case 0x60:
case 0x61:
case 0x63:
case 0x64:
case 0x65:
case 0x66:
case 0x67:
case 0x68:
case 0x69:
case 0x6B:
case 0x6C:
case 0x6D:
case 0x6E:
case 0x6F:
case 0x73:
case 0x77:
case 0x78:
assertTrue(true);
break;
default:
String res = de.getMessage();
if (res.startsWith("ERR_01200_BAD_TRANSITION_FROM_STATE") || res.startsWith("Universal tag ") || res.startsWith("ERR_01005_TRUNCATED_PDU Truncated PDU")) {
assertTrue(true);
} else {
fail("Bad exception : " + res);
return;
}
break;
}
}
stream.clear();
}
assertTrue(true);
}
use of org.apache.directory.api.asn1.ber.Asn1Container in project directory-ldap-api by apache.
the class LdapMessageTest method testDecodeMessageIdMinusOne.
/**
* Test the decoding of null length messageId
*/
@Test
public void testDecodeMessageIdMinusOne() {
Asn1Decoder ldapDecoder = new Asn1Decoder();
ByteBuffer stream = ByteBuffer.allocate(0x05);
stream.put(new byte[] { // LDAPMessage ::=SEQUENCE {
0x30, // LDAPMessage ::=SEQUENCE {
0x03, 0x02, 0x01, // messageID MessageID = -1
(byte) 0xff });
stream.flip();
// Allocate a LdapMessage Container
Asn1Container ldapMessageContainer = new LdapMessageContainer<MessageDecorator<? extends Message>>(codec);
// Decode a BindRequest PDU
try {
ldapDecoder.decode(stream, ldapMessageContainer);
} catch (DecoderException de) {
assertTrue(true);
return;
}
fail("We should not reach this point !");
}
Aggregations