Search in sources :

Example 11 with IntermediateResponseDecorator

use of org.apache.directory.api.ldap.codec.decorators.IntermediateResponseDecorator in project directory-ldap-api by apache.

the class IntermediateResponseTest method testDecodeIntermediateResponseNoValue.

/**
 * Test the decoding of an IntermediateResponse with no value
 */
@Test
public void testDecodeIntermediateResponseNoValue() {
    Asn1Decoder ldapDecoder = new Asn1Decoder();
    ByteBuffer stream = ByteBuffer.allocate(0x16);
    stream.put(new byte[] { // LDAPMessage ::= SEQUENCE {
    0x30, // LDAPMessage ::= SEQUENCE {
    0x14, 0x02, 0x01, // messageID MessageID
    0x01, // CHOICE { ..., intermediateResponse IntermediateResponse, ...
    0x79, // IntermediateResponse ::= [APPLICATION 25] SEQUENCE {
    0x0F, // responseName [0] LDAPOID,
    (byte) 0x80, 0x0D, '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '2' });
    String decodedPdu = Strings.dumpBytes(stream.array());
    stream.flip();
    // Allocate a LdapMessage Container
    LdapMessageContainer<IntermediateResponseDecorator<?>> ldapMessageContainer = new LdapMessageContainer<IntermediateResponseDecorator<?>>(codec);
    // Decode the IntermediateResponse PDU
    try {
        ldapDecoder.decode(stream, ldapMessageContainer);
    } catch (DecoderException de) {
        de.printStackTrace();
        fail(de.getMessage());
    }
    // Check the decoded IntermediateResponse PDU
    IntermediateResponse intermediateResponse = ldapMessageContainer.getMessage();
    assertEquals(1, intermediateResponse.getMessageId());
    assertEquals("1.3.6.1.5.5.2", intermediateResponse.getResponseName());
    assertEquals("", Strings.utf8ToString(intermediateResponse.getResponseValue()));
    // Check the encoding
    try {
        ByteBuffer bb = encoder.encodeMessage(intermediateResponse);
        // Check the length
        assertEquals(0x16, bb.limit());
        String encodedPdu = Strings.dumpBytes(bb.array());
        assertEquals(encodedPdu, decodedPdu);
    } catch (EncoderException ee) {
        ee.printStackTrace();
        fail(ee.getMessage());
    }
}
Also used : LdapMessageContainer(org.apache.directory.api.ldap.codec.api.LdapMessageContainer) DecoderException(org.apache.directory.api.asn1.DecoderException) EncoderException(org.apache.directory.api.asn1.EncoderException) IntermediateResponseDecorator(org.apache.directory.api.ldap.codec.decorators.IntermediateResponseDecorator) IntermediateResponse(org.apache.directory.api.ldap.model.message.IntermediateResponse) 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 12 with IntermediateResponseDecorator

use of org.apache.directory.api.ldap.codec.decorators.IntermediateResponseDecorator in project directory-ldap-api by apache.

the class IntermediateResponseTest method testDecodeExtendedBadRequestName.

/**
 * Test the decoding of a bad name
 */
@Test
public void testDecodeExtendedBadRequestName() {
    Asn1Decoder ldapDecoder = new Asn1Decoder();
    ByteBuffer stream = ByteBuffer.allocate(0x16);
    stream.put(new byte[] { // LDAPMessage ::= SEQUENCE {
    0x30, // LDAPMessage ::= SEQUENCE {
    0x14, 0x02, 0x01, // messageID MessageID
    0x01, // CHOICE { ..., intermediateResponse IntermediateResponse, ...
    0x79, // IntermediateResponse ::= [APPLICATION 25] SEQUENCE {
    0x0F, // responseName [0] LDAPOID,
    (byte) 0x80, 0x0D, '1', '-', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '2' });
    stream.flip();
    // Allocate a LdapMessage Container
    LdapMessageContainer<IntermediateResponseDecorator<?>> ldapMessageContainer = new LdapMessageContainer<IntermediateResponseDecorator<?>>(codec);
    // Decode a IntermediateResponse PDU
    try {
        ldapDecoder.decode(stream, ldapMessageContainer);
        fail("We should never reach this point !!!");
    } catch (DecoderException de) {
        assertTrue(true);
    }
}
Also used : LdapMessageContainer(org.apache.directory.api.ldap.codec.api.LdapMessageContainer) DecoderException(org.apache.directory.api.asn1.DecoderException) IntermediateResponseDecorator(org.apache.directory.api.ldap.codec.decorators.IntermediateResponseDecorator) 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

IntermediateResponseDecorator (org.apache.directory.api.ldap.codec.decorators.IntermediateResponseDecorator)12 ByteBuffer (java.nio.ByteBuffer)10 DecoderException (org.apache.directory.api.asn1.DecoderException)10 Asn1Decoder (org.apache.directory.api.asn1.ber.Asn1Decoder)10 LdapMessageContainer (org.apache.directory.api.ldap.codec.api.LdapMessageContainer)10 AbstractCodecServiceTest (org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)10 Test (org.junit.Test)10 IntermediateResponse (org.apache.directory.api.ldap.model.message.IntermediateResponse)8 EncoderException (org.apache.directory.api.asn1.EncoderException)7 Control (org.apache.directory.api.ldap.model.message.Control)3 CodecControl (org.apache.directory.api.ldap.codec.api.CodecControl)2 AbandonRequestDecorator (org.apache.directory.api.ldap.codec.decorators.AbandonRequestDecorator)1 AddRequestDecorator (org.apache.directory.api.ldap.codec.decorators.AddRequestDecorator)1 AddResponseDecorator (org.apache.directory.api.ldap.codec.decorators.AddResponseDecorator)1 BindRequestDecorator (org.apache.directory.api.ldap.codec.decorators.BindRequestDecorator)1 BindResponseDecorator (org.apache.directory.api.ldap.codec.decorators.BindResponseDecorator)1 CompareRequestDecorator (org.apache.directory.api.ldap.codec.decorators.CompareRequestDecorator)1 CompareResponseDecorator (org.apache.directory.api.ldap.codec.decorators.CompareResponseDecorator)1 DeleteRequestDecorator (org.apache.directory.api.ldap.codec.decorators.DeleteRequestDecorator)1 DeleteResponseDecorator (org.apache.directory.api.ldap.codec.decorators.DeleteResponseDecorator)1