Search in sources :

Example 46 with Asn1Container

use of org.apache.directory.api.asn1.ber.Asn1Container in project directory-ldap-api by apache.

the class LdapDecoderTest method testDecodeSplittedLength.

/**
 * Test the decoding of a split Length.
 *
 * The length is 3 bytes long, but the PDU has been split
 * just after the first byte
 */
@Test
public void testDecodeSplittedLength() {
    Asn1Decoder ldapDecoder = new Asn1Decoder();
    ByteBuffer stream = ByteBuffer.allocate(3);
    stream.put(new byte[] { // LDAPMessage ::=SEQUENCE {
    0x30, // LDAPMessage ::=SEQUENCE {
    (byte) 0x82, // LDAPMessage ::=SEQUENCE {
    0x01 });
    stream.flip();
    // Allocate a LdapMessage Container
    Asn1Container ldapMessageContainer = new LdapMessageContainer<MessageDecorator<? extends Message>>(codec);
    // Decode a BindRequest PDU first block of data
    try {
        ldapDecoder.decode(stream, ldapMessageContainer);
    } catch (DecoderException de) {
        de.printStackTrace();
        fail(de.getMessage());
    }
    assertEquals(TLVStateEnum.LENGTH_STATE_PENDING, ldapMessageContainer.getState());
    // Second block of data
    stream = ByteBuffer.allocate(1);
    stream.put(new byte[] { // End of the length
    (byte) 0x80 });
    stream.flip();
    // Decode a BindRequest PDU second block of data
    try {
        ldapDecoder.decode(stream, ldapMessageContainer);
    } catch (DecoderException de) {
        de.printStackTrace();
        fail(de.getMessage());
    }
    assertEquals(TLVStateEnum.TAG_STATE_START, ldapMessageContainer.getState());
    // Check the decoded length
    assertEquals(384, ldapMessageContainer.getCurrentTLV().getLength());
}
Also used : LdapMessageContainer(org.apache.directory.api.ldap.codec.api.LdapMessageContainer) DecoderException(org.apache.directory.api.asn1.DecoderException) Asn1Container(org.apache.directory.api.asn1.ber.Asn1Container) Asn1Decoder(org.apache.directory.api.asn1.ber.Asn1Decoder) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test) AbstractCodecServiceTest(org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)

Example 47 with Asn1Container

use of org.apache.directory.api.asn1.ber.Asn1Container in project directory-ldap-api by apache.

the class LdapMessageTest method testDecodeMessageIdLengthNull.

/**
 * Test the decoding of null length messageId
 */
@Test
public void testDecodeMessageIdLengthNull() {
    Asn1Decoder ldapDecoder = new Asn1Decoder();
    ByteBuffer stream = ByteBuffer.allocate(0x04);
    stream.put(new byte[] { // LDAPMessage ::=SEQUENCE {
    0x30, // LDAPMessage ::=SEQUENCE {
    0x02, 0x02, // messageID MessageID
    0x00 });
    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 !");
}
Also used : LdapMessageContainer(org.apache.directory.api.ldap.codec.api.LdapMessageContainer) DecoderException(org.apache.directory.api.asn1.DecoderException) Asn1Container(org.apache.directory.api.asn1.ber.Asn1Container) Asn1Decoder(org.apache.directory.api.asn1.ber.Asn1Decoder) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test) AbstractCodecServiceTest(org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)

Example 48 with Asn1Container

use of org.apache.directory.api.asn1.ber.Asn1Container in project directory-ldap-api by apache.

the class LdapMessageTest method testDecodeMessageLengthNull.

/**
 * Test the decoding of null length messageId
 */
@Test
public void testDecodeMessageLengthNull() {
    Asn1Decoder ldapDecoder = new Asn1Decoder();
    ByteBuffer stream = ByteBuffer.allocate(0x02);
    stream.put(new byte[] { // LDAPMessage ::=SEQUENCE {
    0x30, // LDAPMessage ::=SEQUENCE {
    0x00 });
    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 !");
}
Also used : LdapMessageContainer(org.apache.directory.api.ldap.codec.api.LdapMessageContainer) DecoderException(org.apache.directory.api.asn1.DecoderException) Asn1Container(org.apache.directory.api.asn1.ber.Asn1Container) Asn1Decoder(org.apache.directory.api.asn1.ber.Asn1Decoder) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test) AbstractCodecServiceTest(org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)

Aggregations

DecoderException (org.apache.directory.api.asn1.DecoderException)40 Asn1Decoder (org.apache.directory.api.asn1.ber.Asn1Decoder)39 ByteBuffer (java.nio.ByteBuffer)38 Test (org.junit.Test)38 Asn1Container (org.apache.directory.api.asn1.ber.Asn1Container)36 LdapMessageContainer (org.apache.directory.api.ldap.codec.api.LdapMessageContainer)30 AbstractCodecServiceTest (org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)29 TLV (org.apache.directory.api.asn1.ber.tlv.TLV)10 EncoderException (org.apache.directory.api.asn1.EncoderException)6 CancelContainer (org.apache.directory.api.ldap.extras.extended.ads_impl.cancel.CancelContainer)5 CancelDecoder (org.apache.directory.api.ldap.extras.extended.ads_impl.cancel.CancelDecoder)5 Message (org.apache.directory.api.ldap.model.message.Message)4 ResponseCarryingException (org.apache.directory.api.ldap.codec.api.ResponseCarryingException)3 AddResponseImpl (org.apache.directory.api.ldap.model.message.AddResponseImpl)3 BerValue (org.apache.directory.api.asn1.ber.tlv.BerValue)2 BindRequestDecorator (org.apache.directory.api.ldap.codec.decorators.BindRequestDecorator)2 BindRequest (org.apache.directory.api.ldap.model.message.BindRequest)2 CheckNotNullLength (org.apache.directory.api.asn1.actions.CheckNotNullLength)1 MessageDecorator (org.apache.directory.api.ldap.codec.api.MessageDecorator)1 AndFilter (org.apache.directory.api.ldap.codec.search.AndFilter)1