Search in sources :

Example 11 with MessageDecorator

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()));
}
Also used : LdapMessageContainer(org.apache.directory.api.ldap.codec.api.LdapMessageContainer) DecoderException(org.apache.directory.api.asn1.DecoderException) MessageDecorator(org.apache.directory.api.ldap.codec.api.MessageDecorator) Message(org.apache.directory.api.ldap.model.message.Message) Asn1Decoder(org.apache.directory.api.asn1.ber.Asn1Decoder) BindRequest(org.apache.directory.api.ldap.model.message.BindRequest) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test) AbstractCodecServiceTest(org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)

Aggregations

MessageDecorator (org.apache.directory.api.ldap.codec.api.MessageDecorator)11 Message (org.apache.directory.api.ldap.model.message.Message)11 LdapMessageContainer (org.apache.directory.api.ldap.codec.api.LdapMessageContainer)10 ByteBuffer (java.nio.ByteBuffer)8 DecoderException (org.apache.directory.api.asn1.DecoderException)8 AbstractCodecServiceTest (org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)7 Test (org.junit.Test)7 Asn1Decoder (org.apache.directory.api.asn1.ber.Asn1Decoder)6 BindRequest (org.apache.directory.api.ldap.model.message.BindRequest)3 IOException (java.io.IOException)2 ConnectException (java.net.ConnectException)2 UnresolvedAddressException (java.nio.channels.UnresolvedAddressException)2 ArrayList (java.util.ArrayList)2 SchemaBinaryAttributeDetector (org.apache.directory.api.ldap.codec.api.SchemaBinaryAttributeDetector)2 LdapOtherException (org.apache.directory.api.ldap.model.exception.LdapOtherException)2 InvalidConnectionException (org.apache.directory.ldap.client.api.exception.InvalidConnectionException)2 InetSocketAddress (java.net.InetSocketAddress)1 SocketAddress (java.net.SocketAddress)1 TLV (org.apache.directory.api.asn1.ber.tlv.TLV)1 BinaryAttributeDetector (org.apache.directory.api.ldap.codec.api.BinaryAttributeDetector)1