use of org.apache.directory.api.ldap.codec.decorators.BindRequestDecorator in project directory-ldap-api by apache.
the class BindRequestTest method testDecodeBindRequestEmptySimple.
/**
* Test the decoding of a BindRequest with an empty simple
*/
@Test
public void testDecodeBindRequestEmptySimple() {
Asn1Decoder ldapDecoder = new Asn1Decoder();
ByteBuffer stream = ByteBuffer.allocate(0x0E);
stream.put(new byte[] { // LDAPMessage ::=SEQUENCE {
0x30, // LDAPMessage ::=SEQUENCE {
0x0C, 0x02, 0x01, // messageID MessageID
0x01, 0x60, // CHOICE { ..., bindRequest BindRequest, ...
0x07, 0x02, 0x01, // version INTEGER (1..127),
0x03, 0x04, 0x00, (byte) 0x80, 0x00 });
String decodedPdu = Strings.dumpBytes(stream.array());
stream.flip();
// Allocate a LdapMessage Container
LdapMessageContainer<BindRequestDecorator> container = new LdapMessageContainer<BindRequestDecorator>(codec);
// Decode the BindRequest PDU
try {
ldapDecoder.decode(stream, container);
} catch (DecoderException de) {
de.printStackTrace();
fail(de.getMessage());
}
// Check the decoded BindRequest
BindRequest bindRequest = container.getMessage();
assertEquals(1, bindRequest.getMessageId());
assertTrue(bindRequest.isVersion3());
assertEquals("", bindRequest.getName());
assertTrue(bindRequest.isSimple());
assertEquals("", Strings.utf8ToString(bindRequest.getCredentials()));
// Check the encoding
try {
ByteBuffer bb = encoder.encodeMessage(bindRequest);
// Check the length
assertEquals(0x0E, bb.limit());
String encodedPdu = Strings.dumpBytes(bb.array());
assertEquals(encodedPdu, decodedPdu);
} catch (EncoderException ee) {
ee.printStackTrace();
fail(ee.getMessage());
}
}
use of org.apache.directory.api.ldap.codec.decorators.BindRequestDecorator in project directory-ldap-api by apache.
the class BindRequestTest method testDecodeBindRequestBadVersion4.
/**
* Test the decoding of a BindRequest with a bad version (4)
*/
@Test
public void testDecodeBindRequestBadVersion4() {
Asn1Decoder ldapDecoder = new Asn1Decoder();
ByteBuffer stream = ByteBuffer.allocate(0x0A);
stream.put(new byte[] { // LDAPMessage ::=SEQUENCE {
0x30, // LDAPMessage ::=SEQUENCE {
0x08, 0x02, 0x01, // messageID MessageID
0x01, 0x60, // CHOICE { ..., bindRequest BindRequest, ...
0x03, 0x02, 0x01, // version INTEGER (1..127),
0x04 });
stream.flip();
// Allocate a LdapMessage Container
LdapMessageContainer<BindRequestDecorator> container = new LdapMessageContainer<BindRequestDecorator>(codec);
// Decode a BindRequest message
try {
ldapDecoder.decode(stream, container);
} catch (DecoderException de) {
assertTrue(true);
return;
}
fail("We should not reach this point");
}
use of org.apache.directory.api.ldap.codec.decorators.BindRequestDecorator in project directory-ldap-api by apache.
the class BindRequestTest method testDecodeBindRequestBadVersion0.
/**
* Test the decoding of a BindRequest with a bad version (0)
*/
@Test
public void testDecodeBindRequestBadVersion0() {
Asn1Decoder ldapDecoder = new Asn1Decoder();
ByteBuffer stream = ByteBuffer.allocate(0x0A);
stream.put(new byte[] { // LDAPMessage ::=SEQUENCE {
0x30, // LDAPMessage ::=SEQUENCE {
0x08, 0x02, 0x01, // messageID MessageID
0x01, 0x60, // CHOICE { ..., bindRequest BindRequest, ...
0x03, 0x02, 0x01, // version INTEGER (1..127),
0x00 });
stream.flip();
// Allocate a LdapMessage Container
LdapMessageContainer<BindRequestDecorator> container = new LdapMessageContainer<BindRequestDecorator>(codec);
// Decode a BindRequest message
try {
ldapDecoder.decode(stream, container);
} catch (DecoderException de) {
assertTrue(true);
return;
}
fail("We should not reach this point");
}
use of org.apache.directory.api.ldap.codec.decorators.BindRequestDecorator in project directory-ldap-api by apache.
the class BindRequestTest method testDecodeBindRequestBadVersion128.
/**
* Test the decoding of a BindRequest with a bad version (128)
*/
@Test
public void testDecodeBindRequestBadVersion128() {
Asn1Decoder ldapDecoder = new Asn1Decoder();
ByteBuffer stream = ByteBuffer.allocate(0x0C);
stream.put(new byte[] { // LDAPMessage ::=SEQUENCE {
0x30, // LDAPMessage ::=SEQUENCE {
0x0A, 0x02, 0x01, // messageID MessageID
0x01, 0x60, // CHOICE { ..., bindRequest BindRequest, ...
0x04, 0x02, 0x02, 0x00, // version INTEGER (1..127),
(byte) 0x80 });
stream.flip();
// Allocate a LdapMessage Container
LdapMessageContainer<BindRequestDecorator> container = new LdapMessageContainer<BindRequestDecorator>(codec);
// Decode a BindRequest message
try {
ldapDecoder.decode(stream, container);
} catch (DecoderException de) {
assertTrue(true);
return;
}
fail("We should not reach this point");
}
use of org.apache.directory.api.ldap.codec.decorators.BindRequestDecorator in project directory-ldap-api by apache.
the class LdapDecoderTest method testDecodeSplittedPDU.
/**
* Test the decoding of a splitted PDU
*/
@Test
public void testDecodeSplittedPDU() {
Asn1Decoder ldapDecoder = new Asn1Decoder();
ByteBuffer stream = ByteBuffer.allocate(16);
stream.put(new byte[] { // LDAPMessage ::=SEQUENCE {
0x30, // LDAPMessage ::=SEQUENCE {
0x33, 0x02, 0x01, // 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', '=' });
stream.flip();
// Allocate a LdapMessage Container
LdapMessageContainer<BindRequestDecorator> container = new LdapMessageContainer<BindRequestDecorator>(codec);
// Decode a BindRequest PDU first block of data
try {
ldapDecoder.decode(stream, container);
} catch (DecoderException de) {
de.printStackTrace();
fail(de.getMessage());
}
assertEquals(TLVStateEnum.VALUE_STATE_PENDING, container.getState());
// Second block of data
stream = ByteBuffer.allocate(37);
stream.put(new byte[] { 'a', 'k', 'a', 'r', 'a', 's', 'u', 'l', 'u', ',', 'd', 'c', '=', 'e', 'x', 'a', 'm', 'p', 'l', 'e', ',', // authentication
'd', // authentication
'c', // authentication
'=', // authentication
'c', // authentication
'o', // authentication
'm', // authentication
(byte) 0x80, // authentication
0x08, // ...
'p', 'a', 's', 's', 'w', 'o', 'r', 'd' });
stream.flip();
// Decode a BindRequest PDU second block of data
try {
ldapDecoder.decode(stream, container);
} catch (DecoderException de) {
de.printStackTrace();
fail(de.getMessage());
}
assertEquals(container.getState(), TLVStateEnum.PDU_DECODED);
// Check the decoded PDU
BindRequest bindRequest = container.getMessage();
assertEquals(1, bindRequest.getMessageId());
assertTrue(bindRequest.isVersion3());
assertEquals("uid=akarasulu,dc=example,dc=com", bindRequest.getName().toString());
assertTrue(bindRequest.isSimple());
assertEquals("password", Strings.utf8ToString(bindRequest.getCredentials()));
}
Aggregations