Search in sources :

Example 16 with Oid

use of org.apache.directory.api.asn1.util.Oid in project directory-ldap-api by apache.

the class SearchRequestTest method testDecodeSearchRequestSubEntryControl.

/**
 * Test the decoding of a SearchRequest with SubEntry control.
 */
@Test
public void testDecodeSearchRequestSubEntryControl() {
    byte[] asn1BER = new byte[] { 0x30, 0x5D, 0x02, 0x01, // messageID
    0x04, 0x63, 0x33, 0x04, // baseObject: dc=my-domain,dc=com
    0x13, 'd', 'c', '=', 'm', 'y', '-', 'd', 'o', 'm', 'a', 'i', 'n', ',', 'd', 'c', '=', 'c', 'o', 'm', 0x0a, 0x01, // scope: subtree
    0x02, 0x0a, 0x01, // derefAliases: derefAlways
    0x03, 0x02, 0x01, // sizeLimit: 0
    0x00, 0x02, 0x01, // timeLimit: 0
    0x00, 0x01, 0x01, // typesOnly: false
    0x00, (byte) 0x87, // filter: (objectClass=*)
    0x0b, 'o', 'b', 'j', 'e', 'c', 't', 'C', 'l', 'a', 's', 's', 0x30, 0x00, (byte) 0xa0, // controls
    0x23, 0x30, 0x21, 0x04, 0x17, '1', '.', '3', '.', '6', '.', '1', '.', '4', '.', '1', '.', '4', '2', '0', '3', '.', '1', '.', '1', '0', '.', // SubEntry OID
    '1', 0x01, 0x01, // criticality: true
    (byte) 0xFF, 0x04, 0x03, 0x01, 0x01, // SubEntry visibility
    (byte) 0xFF };
    Asn1Decoder ldapDecoder = new Asn1Decoder();
    ByteBuffer stream = ByteBuffer.allocate(asn1BER.length);
    stream.put(asn1BER);
    String decodedPdu = Strings.dumpBytes(stream.array());
    stream.flip();
    LdapMessageContainer<SearchRequestDecorator> ldapMessageContainer = new LdapMessageContainer<SearchRequestDecorator>(codec);
    try {
        ldapDecoder.decode(stream, ldapMessageContainer);
    } catch (DecoderException de) {
        de.printStackTrace();
        fail(de.getMessage());
    }
    assertEquals(TLVStateEnum.PDU_DECODED, ldapMessageContainer.getState());
    SearchRequest searchRequest = ldapMessageContainer.getMessage();
    assertEquals(4, searchRequest.getMessageId());
    assertEquals(1, searchRequest.getControls().size());
    // SubEntry Control
    String subEntryControlOID = "1.3.6.1.4.1.4203.1.10.1";
    Control subEntryControl = searchRequest.getControl(subEntryControlOID);
    assertEquals(subEntryControlOID, subEntryControl.getOid());
    assertTrue(subEntryControl.isCritical());
    assertTrue(subEntryControl instanceof SubentriesDecorator);
    assertTrue(((SubentriesDecorator) subEntryControl).getDecorated().isVisible());
    assertEquals("dc=my-domain,dc=com", searchRequest.getBase().toString());
    assertEquals(SearchScope.SUBTREE, searchRequest.getScope());
    assertEquals(AliasDerefMode.DEREF_ALWAYS, searchRequest.getDerefAliases());
    assertEquals(0, searchRequest.getSizeLimit());
    assertEquals(0, searchRequest.getTimeLimit());
    assertEquals(false, searchRequest.getTypesOnly());
    ExprNode filter = searchRequest.getFilter();
    assertTrue(filter instanceof PresenceNode);
    assertEquals("objectClass", ((PresenceNode) filter).getAttribute());
    // Check the encoding
    try {
        ByteBuffer bb = encoder.encodeMessage(searchRequest);
        // Check the length
        assertEquals(0x5F, bb.limit());
        String encodedPdu = Strings.dumpBytes(bb.array());
        assertEquals(decodedPdu, encodedPdu);
    } catch (EncoderException ee) {
        ee.printStackTrace();
        fail(ee.getMessage());
    }
}
Also used : LdapMessageContainer(org.apache.directory.api.ldap.codec.api.LdapMessageContainer) SearchRequest(org.apache.directory.api.ldap.model.message.SearchRequest) PresenceNode(org.apache.directory.api.ldap.model.filter.PresenceNode) ByteBuffer(java.nio.ByteBuffer) ExprNode(org.apache.directory.api.ldap.model.filter.ExprNode) DecoderException(org.apache.directory.api.asn1.DecoderException) EncoderException(org.apache.directory.api.asn1.EncoderException) Control(org.apache.directory.api.ldap.model.message.Control) SubentriesDecorator(org.apache.directory.api.ldap.codec.controls.search.subentries.SubentriesDecorator) Asn1Decoder(org.apache.directory.api.asn1.ber.Asn1Decoder) SearchRequestDecorator(org.apache.directory.api.ldap.codec.decorators.SearchRequestDecorator) Test(org.junit.Test) AbstractCodecServiceTest(org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)

Example 17 with Oid

use of org.apache.directory.api.asn1.util.Oid in project directory-ldap-api by apache.

the class IntermediateResponseTest method testDecodeEmptyOID.

/**
 * Test the decoding of an empty OID
 */
@Test
public void testDecodeEmptyOID() {
    Asn1Decoder ldapDecoder = new Asn1Decoder();
    ByteBuffer stream = ByteBuffer.allocate(0x09);
    stream.put(new byte[] { // LDAPMessage ::= SEQUENCE {
    0x30, // LDAPMessage ::= SEQUENCE {
    0x07, 0x02, 0x01, // messageID MessageID
    0x01, // CHOICE { ..., intermediateResponse IntermediateResponse, ...
    0x79, // IntermediateResponse ::= [APPLICATION 25] SEQUENCE {
    0x02, (byte) 0x80, 0x00 });
    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

DecoderException (org.apache.directory.api.asn1.DecoderException)14 ByteBuffer (java.nio.ByteBuffer)7 Asn1Decoder (org.apache.directory.api.asn1.ber.Asn1Decoder)7 LdapMessageContainer (org.apache.directory.api.ldap.codec.api.LdapMessageContainer)7 AbstractCodecServiceTest (org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)7 Test (org.junit.Test)7 TLV (org.apache.directory.api.asn1.ber.tlv.TLV)6 EncoderException (org.apache.directory.api.asn1.EncoderException)3 Control (org.apache.directory.api.ldap.model.message.Control)3 ExtendedRequest (org.apache.directory.api.ldap.model.message.ExtendedRequest)3 SearchRequest (org.apache.directory.api.ldap.model.message.SearchRequest)3 Asn1Container (org.apache.directory.api.asn1.ber.Asn1Container)2 ExtendedRequestDecorator (org.apache.directory.api.ldap.codec.decorators.ExtendedRequestDecorator)2 ExtendedResponseDecorator (org.apache.directory.api.ldap.codec.decorators.ExtendedResponseDecorator)2 SearchRequestDecorator (org.apache.directory.api.ldap.codec.decorators.SearchRequestDecorator)2 ExprNode (org.apache.directory.api.ldap.model.filter.ExprNode)2 BigInteger (java.math.BigInteger)1 BufferOverflowException (java.nio.BufferOverflowException)1 NamingException (javax.naming.NamingException)1 Oid (org.apache.directory.api.asn1.util.Oid)1