Search in sources :

Example 16 with Asn1Container

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

the class CancelRequestTest method testDecodeCancelBadCancelId.

/**
 * Test a Cancel message with a bad cancelId
 */
@Test
public void testDecodeCancelBadCancelId() {
    Asn1Decoder cancelDecoder = new CancelDecoder();
    ByteBuffer stream = ByteBuffer.allocate(0x08);
    stream.put(new byte[] { 0x30, 0x06, 0x02, 0x04, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF }).flip();
    // Allocate a Cancel Container
    Asn1Container cancelContainer = new CancelContainer();
    // Decode a Cancel message
    try {
        cancelDecoder.decode(stream, cancelContainer);
        fail("CancelID expected");
    } catch (DecoderException de) {
        assertTrue(true);
    }
}
Also used : DecoderException(org.apache.directory.api.asn1.DecoderException) Asn1Container(org.apache.directory.api.asn1.ber.Asn1Container) CancelDecoder(org.apache.directory.api.ldap.extras.extended.ads_impl.cancel.CancelDecoder) Asn1Decoder(org.apache.directory.api.asn1.ber.Asn1Decoder) CancelContainer(org.apache.directory.api.ldap.extras.extended.ads_impl.cancel.CancelContainer) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 17 with Asn1Container

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

the class CancelRequestTest method testDecodeCancel.

/**
 * Test the normal Cancel message
 */
@Test
public void testDecodeCancel() {
    Asn1Decoder cancelDecoder = new CancelDecoder();
    ByteBuffer stream = ByteBuffer.allocate(0x05);
    stream.put(new byte[] { 0x30, 0x03, 0x02, 0x01, 0x01 }).flip();
    String decodedPdu = Strings.dumpBytes(stream.array());
    // Allocate a Cancel Container
    Asn1Container cancelContainer = new CancelContainer();
    // Decode a Cancel message
    try {
        cancelDecoder.decode(stream, cancelContainer);
    } catch (DecoderException de) {
        de.printStackTrace();
        fail(de.getMessage());
    }
    CancelRequestDecorator cancel = ((CancelContainer) cancelContainer).getCancel();
    assertEquals(1, cancel.getCancelId());
    // Check the encoding
    try {
        ByteBuffer bb = cancel.encodeInternal();
        String encodedPdu = Strings.dumpBytes(bb.array());
        assertEquals(encodedPdu, decodedPdu);
    } catch (EncoderException ee) {
        ee.printStackTrace();
        fail(ee.getMessage());
    }
}
Also used : DecoderException(org.apache.directory.api.asn1.DecoderException) EncoderException(org.apache.directory.api.asn1.EncoderException) Asn1Container(org.apache.directory.api.asn1.ber.Asn1Container) CancelDecoder(org.apache.directory.api.ldap.extras.extended.ads_impl.cancel.CancelDecoder) Asn1Decoder(org.apache.directory.api.asn1.ber.Asn1Decoder) CancelRequestDecorator(org.apache.directory.api.ldap.extras.extended.ads_impl.cancel.CancelRequestDecorator) CancelContainer(org.apache.directory.api.ldap.extras.extended.ads_impl.cancel.CancelContainer) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 18 with Asn1Container

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

the class CancelRequestTest method testDecodeCancelEmptyCancelId.

/**
 * Test a Cancel message with an empty cancelId
 */
@Test
public void testDecodeCancelEmptyCancelId() {
    Asn1Decoder cancelDecoder = new CancelDecoder();
    ByteBuffer stream = ByteBuffer.allocate(0x04);
    stream.put(new byte[] { 0x30, 0x02, 0x02, 0x00 }).flip();
    // Allocate a Cancel Container
    Asn1Container cancelContainer = new CancelContainer();
    // Decode a Cancel message
    try {
        cancelDecoder.decode(stream, cancelContainer);
        fail("CancelID expected");
    } catch (DecoderException de) {
        assertTrue(true);
    }
}
Also used : DecoderException(org.apache.directory.api.asn1.DecoderException) Asn1Container(org.apache.directory.api.asn1.ber.Asn1Container) CancelDecoder(org.apache.directory.api.ldap.extras.extended.ads_impl.cancel.CancelDecoder) Asn1Decoder(org.apache.directory.api.asn1.ber.Asn1Decoder) CancelContainer(org.apache.directory.api.ldap.extras.extended.ads_impl.cancel.CancelContainer) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 19 with Asn1Container

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

the class CancelRequestTest method testDecodeCancelMoreThanOneCancelId.

/**
 * Test a Cancel message with more than one cancelId
 */
@Test
public void testDecodeCancelMoreThanOneCancelId() {
    Asn1Decoder cancelDecoder = new CancelDecoder();
    ByteBuffer stream = ByteBuffer.allocate(0x08);
    stream.put(new byte[] { 0x30, 0x06, 0x02, 0x01, 0x01, 0x02, 0x01, 0x02 }).flip();
    // Allocate a Cancel Container
    Asn1Container cancelContainer = new CancelContainer();
    // Decode a Cancel message
    try {
        cancelDecoder.decode(stream, cancelContainer);
        fail("CancelID expected");
    } catch (DecoderException de) {
        assertTrue(true);
    }
}
Also used : DecoderException(org.apache.directory.api.asn1.DecoderException) Asn1Container(org.apache.directory.api.asn1.ber.Asn1Container) CancelDecoder(org.apache.directory.api.ldap.extras.extended.ads_impl.cancel.CancelDecoder) Asn1Decoder(org.apache.directory.api.asn1.ber.Asn1Decoder) CancelContainer(org.apache.directory.api.ldap.extras.extended.ads_impl.cancel.CancelContainer) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 20 with Asn1Container

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

the class WhoAmIResponseTest method testDecodeWhoAmINoWhoAmIAuthzIdDN.

/**
 * Test a WhoAmI message with a DN authzId
 */
@Test
public void testDecodeWhoAmINoWhoAmIAuthzIdDN() {
    Asn1Decoder whoAmIResponseDecoder = new WhoAmIResponseDecoder();
    ByteBuffer stream = ByteBuffer.allocate(0x0E);
    stream.put(new byte[] { 0x04, 0x0C, 'd', 'n', ':', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm' }).flip();
    String decodedPdu = Strings.dumpBytes(stream.array());
    // Allocate a WhoAmI Container
    Asn1Container whoAmIResponseContainer = new WhoAmIResponseContainer();
    // Decode a WhoAmI message
    try {
        whoAmIResponseDecoder.decode(stream, whoAmIResponseContainer);
    } catch (DecoderException de) {
        fail();
    }
    WhoAmIResponseDecorator whoAmIResponse = ((WhoAmIResponseContainer) whoAmIResponseContainer).getWhoAmIResponse();
    assertNotNull(whoAmIResponse.getAuthzId());
    assertEquals("dn:ou=system", Strings.utf8ToString(whoAmIResponse.getAuthzId()));
    // Check the encoding
    try {
        ByteBuffer bb = whoAmIResponse.encodeInternal();
        String encodedPdu = Strings.dumpBytes(bb.array());
        assertEquals(encodedPdu, decodedPdu);
    } catch (EncoderException ee) {
        ee.printStackTrace();
        fail(ee.getMessage());
    }
}
Also used : DecoderException(org.apache.directory.api.asn1.DecoderException) EncoderException(org.apache.directory.api.asn1.EncoderException) Asn1Container(org.apache.directory.api.asn1.ber.Asn1Container) Asn1Decoder(org.apache.directory.api.asn1.ber.Asn1Decoder) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

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