Search in sources :

Example 11 with GreaterEqNode

use of org.apache.directory.api.ldap.model.filter.GreaterEqNode in project directory-ldap-api by apache.

the class SearchRequestTest method testDecodeSearchRequestEmptyGreaterOrEqualEmptyAttrValueEmpty.

/**
 * Test the decoding of a SearchRequest with a greaterOrEqual filter and an
 * empty attributeValue, and an empty attribute List
 */
@Test
public void testDecodeSearchRequestEmptyGreaterOrEqualEmptyAttrValueEmpty() {
    byte[] asn1BER = new byte[] { 0x30, 0x43, 0x02, 0x01, // messageID
    0x04, 0x63, 0x3E, 0x04, // baseObject 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', 0x0A, 0x01, 0x01, 0x0A, 0x01, 0x03, 0x02, 0x01, 0x00, 0x02, 0x01, 0x00, 0x01, 0x01, (byte) 0xFF, (byte) 0xA5, 0x08, 0x04, 0x04, 't', 'e', 's', 't', 0x04, 0x00, 0x30, // AttributeDescriptionList ::= SEQUENCE
    0x02, // OF AttributeDescription
    0x04, 0x00 };
    Asn1Decoder ldapDecoder = new Asn1Decoder();
    ByteBuffer stream = ByteBuffer.allocate(asn1BER.length);
    stream.put(asn1BER);
    stream.flip();
    // Allocate a LdapMessage Container
    LdapMessageContainer<SearchRequestDecorator> ldapMessageContainer = new LdapMessageContainer<SearchRequestDecorator>(codec);
    // Decode a SearchRequest message
    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("uid=akarasulu,dc=example,dc=com", searchRequest.getBase().toString());
    assertEquals(SearchScope.ONELEVEL, searchRequest.getScope());
    assertEquals(AliasDerefMode.DEREF_ALWAYS, searchRequest.getDerefAliases());
    assertEquals(0, searchRequest.getSizeLimit());
    assertEquals(0, searchRequest.getTimeLimit());
    assertEquals(true, searchRequest.getTypesOnly());
    // >=
    GreaterEqNode<?> greaterOrEqual = (GreaterEqNode<?>) searchRequest.getFilter();
    assertNotNull(greaterOrEqual);
    assertEquals("test", greaterOrEqual.getAttribute());
    assertEquals("", greaterOrEqual.getValue().getValue());
    List<String> attributes = searchRequest.getAttributes();
    assertEquals(0, attributes.size());
}
Also used : LdapMessageContainer(org.apache.directory.api.ldap.codec.api.LdapMessageContainer) DecoderException(org.apache.directory.api.asn1.DecoderException) SearchRequest(org.apache.directory.api.ldap.model.message.SearchRequest) GreaterEqNode(org.apache.directory.api.ldap.model.filter.GreaterEqNode) Asn1Decoder(org.apache.directory.api.asn1.ber.Asn1Decoder) ByteBuffer(java.nio.ByteBuffer) SearchRequestDecorator(org.apache.directory.api.ldap.codec.decorators.SearchRequestDecorator) Test(org.junit.Test) AbstractCodecServiceTest(org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)

Example 12 with GreaterEqNode

use of org.apache.directory.api.ldap.model.filter.GreaterEqNode in project directory-ldap-api by apache.

the class SearchRequestTest method testDecodeSearchRequestEmptyGreaterOrEqualEmptyAttrValue.

/**
 * Test the decoding of a SearchRequest with a greaterOrEqual filter and an
 * empty attributeValue, and an empty attribute List
 */
@Test
public void testDecodeSearchRequestEmptyGreaterOrEqualEmptyAttrValue() {
    byte[] asn1BER = new byte[] { 0x30, 0x41, 0x02, 0x01, // messageID
    0x04, 0x63, 0x3C, 0x04, // baseObject 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', 0x0A, 0x01, 0x01, 0x0A, 0x01, 0x03, 0x02, 0x01, 0x00, 0x02, 0x01, 0x00, 0x01, 0x01, (byte) 0xFF, (byte) 0xA5, 0x08, 0x04, 0x04, 't', 'e', 's', 't', 0x04, 0x00, 0x30, // AttributeDescriptionList ::= SEQUENCE
    0x00 // OF AttributeDescription
    };
    Asn1Decoder ldapDecoder = new Asn1Decoder();
    ByteBuffer stream = ByteBuffer.allocate(asn1BER.length);
    stream.put(asn1BER);
    String decodedPdu = Strings.dumpBytes(stream.array());
    stream.flip();
    // Allocate a LdapMessage Container
    LdapMessageContainer<SearchRequestDecorator> ldapMessageContainer = new LdapMessageContainer<SearchRequestDecorator>(codec);
    // Decode a SearchRequest message
    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("uid=akarasulu,dc=example,dc=com", searchRequest.getBase().toString());
    assertEquals(SearchScope.ONELEVEL, searchRequest.getScope());
    assertEquals(AliasDerefMode.DEREF_ALWAYS, searchRequest.getDerefAliases());
    assertEquals(0, searchRequest.getSizeLimit());
    assertEquals(0, searchRequest.getTimeLimit());
    assertEquals(true, searchRequest.getTypesOnly());
    // >=
    GreaterEqNode<?> greaterOrEqual = (GreaterEqNode<?>) searchRequest.getFilter();
    assertNotNull(greaterOrEqual);
    assertEquals("test", greaterOrEqual.getAttribute());
    assertEquals("", greaterOrEqual.getValue().getValue());
    List<String> attributes = searchRequest.getAttributes();
    assertEquals(0, attributes.size());
    // attributes may have been reordered
    try {
        ByteBuffer bb = encoder.encodeMessage(searchRequest);
        // Check the length
        assertEquals(0x43, 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) SearchRequest(org.apache.directory.api.ldap.model.message.SearchRequest) ByteBuffer(java.nio.ByteBuffer) DecoderException(org.apache.directory.api.asn1.DecoderException) EncoderException(org.apache.directory.api.asn1.EncoderException) GreaterEqNode(org.apache.directory.api.ldap.model.filter.GreaterEqNode) 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 13 with GreaterEqNode

use of org.apache.directory.api.ldap.model.filter.GreaterEqNode in project directory-ldap-api by apache.

the class SearchRequestTest method testDecodeSearchRequestAnd_OrPrPr_NotGEq.

/**
 * Test the decoding of a SearchRequest
 * (&(|(abcdef=*)(ghijkl=*))(!(e>=f)))
 */
@Test
public void testDecodeSearchRequestAnd_OrPrPr_NotGEq() {
    Asn1Decoder ldapDecoder = new Asn1Decoder();
    ByteBuffer stream = ByteBuffer.allocate(0x3B);
    stream.put(new byte[] { // LDAPMessage ::=SEQUENCE {
    0x30, // LDAPMessage ::=SEQUENCE {
    0x39, 0x02, 0x01, // messageID MessageID
    0x01, 0x63, // CHOICE { ...,
    0x34, // SearchRequest ::= APPLICATION[3] SEQUENCE {
    0x04, // baseObject LDAPDN,
    0x03, 'a', '=', 'b', 0x0A, 0x01, // scope ENUMERATED {
    0x01, // wholeSubtree (2) },
    0x0A, 0x01, // derefAliases ENUMERATED {
    0x03, // derefAlways (3) },
    0x02, 0x01, // sizeLimit INTEGER (0 .. maxInt), (0)
    0x00, 0x02, 0x01, // timeLimit INTEGER (0 .. maxInt), (1000)
    0x00, 0x01, 0x01, // typesOnly BOOLEAN, (TRUE)
    (byte) 0xFF, // filter Filter,
    (byte) 0xA0, // Filter ::= CHOICE { and             [0] SET OF Filter,
    0x1C, (byte) 0xA1, // Filter ::= CHOICE { or             [0] SET OF Filter,
    0x10, (byte) 0x87, // present [7] AttributeDescription,
    0x06, 'a', 'b', // AttributeDescription ::= LDAPString
    'c', 'd', 'e', 'f', (byte) 0x87, // present [7] AttributeDescription,
    0x06, 'g', 'h', // AttributeDescription ::= LDAPString
    'i', 'j', 'k', 'l', (byte) 0xA2, // Filter ::= CHOICE { not             Filter,
    0x08, (byte) 0xA5, // greaterOrEqual [3] Assertion,
    0x06, // Assertion ::= SEQUENCE {
    0x04, 0x01, // attributeDesc AttributeDescription (LDAPString),
    'e', 0x04, 0x01, // assertionValue AssertionValue (OCTET STRING) }
    'f', 0x30, // AttributeDescriptionList ::= SEQUENCE OF AttributeDescription
    0x00 });
    String decodedPdu = Strings.dumpBytes(stream.array());
    stream.flip();
    // Allocate a BindRequest Container
    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(1, searchRequest.getMessageId());
    assertEquals("a=b", searchRequest.getBase().toString());
    assertEquals(SearchScope.ONELEVEL, searchRequest.getScope());
    assertEquals(AliasDerefMode.DEREF_ALWAYS, searchRequest.getDerefAliases());
    assertEquals(0, searchRequest.getSizeLimit());
    assertEquals(0, searchRequest.getTimeLimit());
    assertEquals(true, searchRequest.getTypesOnly());
    // (&(...
    ExprNode filter = searchRequest.getFilter();
    AndNode andNode = (AndNode) filter;
    assertNotNull(andNode);
    List<ExprNode> andNodes = andNode.getChildren();
    assertEquals(2, andNodes.size());
    // (&(|(..
    OrNode orFilter = (OrNode) andNodes.get(0);
    assertNotNull(orFilter);
    List<ExprNode> orNodes = orFilter.getChildren();
    assertEquals(2, orNodes.size());
    // (&(&(abcdef=*)...
    PresenceNode presenceNode = (PresenceNode) orNodes.get(0);
    assertNotNull(presenceNode);
    assertEquals("abcdef", presenceNode.getAttribute());
    // (&(&(abcdef=*)(ghijkl=*))...
    presenceNode = (PresenceNode) orNodes.get(1);
    assertNotNull(presenceNode);
    assertEquals("ghijkl", presenceNode.getAttribute());
    // (&(&(abcdef=*)(ghijkl=*))(&...
    NotNode notNode = (NotNode) andNodes.get(1);
    assertNotNull(notNode);
    // (&(&(abcdef=*)(ghijkl=*))(&(e>=f)))
    GreaterEqNode<?> greaterEqNode = (GreaterEqNode<?>) notNode.getFirstChild();
    assertNotNull(greaterEqNode);
    assertEquals("e", greaterEqNode.getAttribute());
    assertEquals("f", greaterEqNode.getValue().getValue());
    List<String> attributes = searchRequest.getAttributes();
    assertEquals(0, attributes.size());
    // attributes may have been reordered
    try {
        ByteBuffer bb = encoder.encodeMessage(searchRequest);
        // Check the length
        assertEquals(0x3B, bb.limit());
        String encodedPdu = Strings.dumpBytes(bb.array());
        assertEquals(encodedPdu.substring(0, 0x3B), decodedPdu.substring(0, 0x3B));
    } 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) NotNode(org.apache.directory.api.ldap.model.filter.NotNode) PresenceNode(org.apache.directory.api.ldap.model.filter.PresenceNode) AndNode(org.apache.directory.api.ldap.model.filter.AndNode) 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) GreaterEqNode(org.apache.directory.api.ldap.model.filter.GreaterEqNode) Asn1Decoder(org.apache.directory.api.asn1.ber.Asn1Decoder) SearchRequestDecorator(org.apache.directory.api.ldap.codec.decorators.SearchRequestDecorator) OrNode(org.apache.directory.api.ldap.model.filter.OrNode) Test(org.junit.Test) AbstractCodecServiceTest(org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)

Aggregations

GreaterEqNode (org.apache.directory.api.ldap.model.filter.GreaterEqNode)13 SearchRequest (org.apache.directory.api.ldap.model.message.SearchRequest)9 Test (org.junit.Test)9 ExprNode (org.apache.directory.api.ldap.model.filter.ExprNode)8 DecoderException (org.apache.directory.api.asn1.DecoderException)7 AndNode (org.apache.directory.api.ldap.model.filter.AndNode)7 OrNode (org.apache.directory.api.ldap.model.filter.OrNode)7 ByteBuffer (java.nio.ByteBuffer)6 Asn1Decoder (org.apache.directory.api.asn1.ber.Asn1Decoder)6 LdapMessageContainer (org.apache.directory.api.ldap.codec.api.LdapMessageContainer)6 SearchRequestDecorator (org.apache.directory.api.ldap.codec.decorators.SearchRequestDecorator)6 AbstractCodecServiceTest (org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)6 NotNode (org.apache.directory.api.ldap.model.filter.NotNode)6 PresenceNode (org.apache.directory.api.ldap.model.filter.PresenceNode)6 EncoderException (org.apache.directory.api.asn1.EncoderException)5 ApproximateNode (org.apache.directory.api.ldap.model.filter.ApproximateNode)5 Value (org.apache.directory.api.ldap.model.entry.Value)4 EqualityNode (org.apache.directory.api.ldap.model.filter.EqualityNode)4 ExtensibleNode (org.apache.directory.api.ldap.model.filter.ExtensibleNode)4 LessEqNode (org.apache.directory.api.ldap.model.filter.LessEqNode)4