use of org.apache.directory.api.ldap.codec.api.MessageDecorator in project directory-ldap-api by apache.
the class LdapDecoderTest method testDecodeFull.
/**
* Test the decoding of a full PDU
*/
@Test
public void testDecodeFull() {
Asn1Decoder ldapDecoder = new Asn1Decoder();
LdapMessageContainer<MessageDecorator<? extends Message>> container = new LdapMessageContainer<MessageDecorator<? extends Message>>(codec);
ByteBuffer stream = ByteBuffer.allocate(0x35);
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', '=', '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();
// Decode a BindRequest PDU
try {
ldapDecoder.decode(stream, container);
} catch (DecoderException de) {
de.printStackTrace();
fail(de.getMessage());
}
assertEquals(TLVStateEnum.PDU_DECODED, container.getState());
// Check the decoded PDU
BindRequest 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