use of org.apache.directory.api.ldap.codec.decorators.SearchRequestDecorator in project directory-ldap-api by apache.
the class SearchRequestSubstringTest method testDecodeSearchRequestSubstringInitialAnyFinal.
/**
* Test the decoding of a SearchRequest with a substring filter. Test the
* initial filter : (objectclass=t*t*t)
*/
@Test
public void testDecodeSearchRequestSubstringInitialAnyFinal() {
Asn1Decoder ldapDecoder = new Asn1Decoder();
ByteBuffer stream = ByteBuffer.allocate(0x6A);
stream.put(new byte[] { 0x30, // LDAPMessage ::=SEQUENCE {
0x68, 0x02, 0x01, // messageID MessageID
0x01, 0x63, // CHOICE { ..., searchRequest SearchRequest, ...
0x63, // SearchRequest ::= APPLICATION[3] SEQUENCE {
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, // scope
0x01, // wholeSubtree (2) },
0x0A, 0x01, // derefAliases ENUMERATED {
0x03, // sizeLimit INTEGER (0 .. maxInt), (1000)
0x02, 0x02, 0x03, (byte) 0xE8, // timeLimit INTEGER (0 .. maxInt), (1000)
0x02, 0x02, 0x03, (byte) 0xE8, 0x01, 0x01, // typesOnly
(byte) 0xFF, // filter Filter,
(byte) 0xA4, // Filter ::= CHOICE {
0x18, // SubstringFilter ::= SEQUENCE {
0x04, // type AttributeDescription,
0x0B, 'o', 'b', 'j', 'e', 'c', 't', 'c', 'l', 'a', 's', 's', 0x30, 0x09, (byte) 0x80, 0x01, //
't', (byte) 0x81, 0x01, //
't', (byte) 0x82, 0x01, //
't', 0x30, // AttributeDescriptionList ::= SEQUENCE OF
0x15, // AttributeDescription
0x04, 0x05, 'a', 't', 't', 'r', // AttributeDescription
'0', // ::= LDAPString
0x04, 0x05, 'a', 't', 't', 'r', // AttributeDescription
'1', // ::= LDAPString
0x04, 0x05, 'a', 't', 't', 'r', // AttributeDescription ::=
'2' // LDAPString
});
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());
}
SearchRequest searchRequest = ldapMessageContainer.getMessage();
assertEquals(1, searchRequest.getMessageId());
assertEquals("uid=akarasulu,dc=example,dc=com", searchRequest.getBase().toString());
assertEquals(SearchScope.ONELEVEL, searchRequest.getScope());
assertEquals(AliasDerefMode.DEREF_ALWAYS, searchRequest.getDerefAliases());
assertEquals(1000, searchRequest.getSizeLimit());
assertEquals(1000, searchRequest.getTimeLimit());
assertEquals(true, searchRequest.getTypesOnly());
// (objectclass=t*)
ExprNode node = searchRequest.getFilter();
SubstringNode substringNode = (SubstringNode) node;
assertNotNull(substringNode);
assertEquals("objectclass", substringNode.getAttribute());
assertEquals("t", substringNode.getInitial());
assertEquals("t", substringNode.getAny().get(0));
assertEquals("t", substringNode.getFinal());
// The attributes
List<String> attributes = searchRequest.getAttributes();
for (String attribute : attributes) {
assertNotNull(attribute);
}
// attributes may have been reordered
try {
ByteBuffer bb = encoder.encodeMessage(searchRequest);
// Check the length
assertEquals(0x6A, bb.limit());
String encodedPdu = Strings.dumpBytes(bb.array());
assertEquals(encodedPdu.substring(0, 0x5B), decodedPdu.substring(0, 0x5B));
} catch (EncoderException ee) {
ee.printStackTrace();
fail(ee.getMessage());
}
}
use of org.apache.directory.api.ldap.codec.decorators.SearchRequestDecorator in project directory-ldap-api by apache.
the class SearchRequestSubstringTest method testDecodeSearchRequestEmptySubstringFilter.
/**
* Test the decoding of a SearchRequest with an empty Substring filter
*/
@Test
public void testDecodeSearchRequestEmptySubstringFilter() {
byte[] asn1BER = new byte[] { 0x30, 0x3B, 0x02, 0x01, // messageID
0x04, 0x63, 0x36, 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) 0xA4, 0x00, 0x30, // AttributeDescriptionList ::= SEQUENCE OF AttributeDescription
0x02, 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) {
assertTrue(true);
return;
}
fail("We should not reach this point");
}
use of org.apache.directory.api.ldap.codec.decorators.SearchRequestDecorator in project directory-ldap-api by apache.
the class SearchRequestSubstringTest method testDecodeSearchRequestSubstringFilterEmptySubstrings.
/**
* Test the decoding of a SearchRequest with a Substring filter and an empty
* Substring
*/
@Test
public void testDecodeSearchRequestSubstringFilterEmptySubstrings() {
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) 0xA4, 0x08, 0x04, 0x04, 't', 'e', 's', 't', 0x30, 0x00, 0x30, // AttributeDescriptionList ::= SEQUENCE OF AttributeDescription
0x02, 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) {
assertTrue(true);
return;
}
fail("We should not reach this point");
}
use of org.apache.directory.api.ldap.codec.decorators.SearchRequestDecorator in project directory-ldap-api by apache.
the class SearchRequestSubstringTest method testDecodeSearchRequestSubstringFilterEmptyType.
/**
* Test the decoding of a SearchRequest with a Substring filter and an empty
* Substring
*/
@Test
public void testDecodeSearchRequestSubstringFilterEmptyType() {
byte[] asn1BER = new byte[] { 0x30, 0x3D, 0x02, 0x01, // messageID
0x04, 0x63, 0x38, 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) 0xA4, 0x02, 0x04, 0x00, 0x30, // AttributeDescriptionList ::= SEQUENCE OF AttributeDescription
0x02, 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) {
assertTrue(true);
return;
}
fail("We should not reach this point");
}
use of org.apache.directory.api.ldap.codec.decorators.SearchRequestDecorator in project directory-ldap-api by apache.
the class SearchRequestTest method testDecodeSearchRequestPresentNoControls.
/**
* Test the decoding of a SearchRequest with no controls. Test the present
* filter : =* The search filter is :
* (&(|(objectclass=*)(ou=*))(!(objectclass>=ttt)))
*/
@Test
public void testDecodeSearchRequestPresentNoControls() {
Asn1Decoder ldapDecoder = new Asn1Decoder();
ByteBuffer stream = ByteBuffer.allocate(0x7B);
stream.put(new byte[] { 0x30, // LDAPMessage ::=SEQUENCE {
0x79, 0x02, 0x01, // messageID MessageID
0x01, 0x63, // CHOICE { ..., searchRequest SearchRequest, ...
0x74, // SearchRequest ::= APPLICATION[3] SEQUENCE {
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, // scope
0x01, // wholeSubtree (2) },
0x0A, 0x01, // derefAliases ENUMERATED {
0x03, // sizeLimit INTEGER (0 .. maxInt), (1000)
0x02, 0x02, 0x03, (byte) 0xE8, // timeLimit INTEGER (0 .. maxInt), (1000)
0x02, 0x02, 0x03, (byte) 0xE8, 0x01, 0x01, // typesOnly
(byte) 0xFF, // filter Filter,
(byte) 0xA0, // Filter ::= CHOICE {
0x29, // and [0] SET OF Filter,
(byte) 0xA1, // or [1] SET of Filter,
0x11, (byte) 0x87, // present [7] AttributeDescription,
0x0B, // AttributeDescription ::= LDAPString
'o', 'b', 'j', 'e', 'c', 't', 'c', 'l', 'a', 's', 's', // assertionValue AssertionValue (OCTET STRING) }
(byte) 0x87, 0x02, 'o', // present [7]
'u', // AttributeDescription ::= LDAPString
(byte) 0xA2, // not [2] Filter,
0x14, (byte) 0xA5, // greaterOrEqual [5]
0x12, // attributeDesc AttributeDescription (LDAPString),
0x04, 0x0B, 'o', 'b', 'j', 'e', 'c', 't', 'c', 'l', 'a', 's', 's', // assertionValue AssertionValue (OCTET STRING) }
0x04, 0x03, 't', 't', 't', // attributes AttributeDescriptionList }
0x30, // AttributeDescriptionList ::= SEQUENCE OF
0x15, // AttributeDescription
0x04, 0x05, 'a', 't', 't', 'r', // AttributeDescription
'0', // ::= LDAPString
0x04, 0x05, 'a', 't', 't', 'r', // AttributeDescription
'1', // ::= LDAPString
0x04, 0x05, 'a', 't', 't', 'r', // AttributeDescription ::=
'2' // LDAPString
});
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("uid=akarasulu,dc=example,dc=com", searchRequest.getBase().toString());
assertEquals(SearchScope.ONELEVEL, searchRequest.getScope());
assertEquals(AliasDerefMode.DEREF_ALWAYS, searchRequest.getDerefAliases());
assertEquals(1000, searchRequest.getSizeLimit());
assertEquals(1000, 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);
// (& (| (objectclass=*) (...
List<ExprNode> orNodes = orFilter.getChildren();
assertEquals(2, orNodes.size());
PresenceNode presenceNode = (PresenceNode) orNodes.get(0);
assertNotNull(presenceNode);
assertEquals("objectclass", presenceNode.getAttribute());
// (& (| (objectclass=*) (ou=*) ) (...
presenceNode = (PresenceNode) orNodes.get(1);
assertNotNull(presenceNode);
assertEquals("ou", presenceNode.getAttribute());
// (& (| (objectclass=*) (ou=*) ) (! ...
NotNode notNode = (NotNode) andNodes.get(1);
assertNotNull(notNode);
// (& (| (objectclass=*) (ou=*) ) (! (objectclass>=ttt) ) )
GreaterEqNode<?> greaterOrEqual = (GreaterEqNode<?>) notNode.getFirstChild();
assertNotNull(greaterOrEqual);
assertEquals("objectclass", greaterOrEqual.getAttribute());
assertEquals("ttt", greaterOrEqual.getValue().getValue());
// The attributes
List<String> attributes = searchRequest.getAttributes();
for (String attribute : attributes) {
assertNotNull(attribute);
}
// attributes may have been reordered
try {
ByteBuffer bb = encoder.encodeMessage(searchRequest);
// Check the length
assertEquals(0x7B, bb.limit());
String encodedPdu = Strings.dumpBytes(bb.array());
assertEquals(encodedPdu.substring(0, 0x6C), decodedPdu.substring(0, 0x6C));
} catch (EncoderException ee) {
ee.printStackTrace();
fail(ee.getMessage());
}
}
Aggregations