You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2005/06/07 00:39:05 UTC
svn commit: r185081 -
/directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/SearchRequestTest.java
Author: elecharny
Date: Mon Jun 6 15:39:04 2005
New Revision: 185081
URL: http://svn.apache.org/viewcvs?rev=185081&view=rev
Log:
Added the FIRST working test case for a searchRequest message ! Lot of sweat and work...
At least, it correctly decode a partial request.
Not finished yet. (The PDU is incorrect, it lacks the attributes descriptions at the end...)
Added:
directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/SearchRequestTest.java
Added: directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/SearchRequestTest.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/SearchRequestTest.java?rev=185081&view=auto
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/SearchRequestTest.java (added)
+++ directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/SearchRequestTest.java Mon Jun 6 15:39:04 2005
@@ -0,0 +1,273 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.asn1.ldap.codec;
+
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+
+import org.apache.asn1.DecoderException;
+import org.apache.asn1.ber.Asn1Decoder;
+import org.apache.asn1.ber.containers.IAsn1Container;
+import org.apache.asn1.ldap.pojo.AttributeValueAssertionPOJO;
+import org.apache.asn1.ldap.pojo.LdapMessagePOJO;
+import org.apache.asn1.ldap.pojo.SearchRequestPOJO;
+import org.apache.asn1.ldap.pojo.filters.AndFilterPOJO;
+import org.apache.asn1.ldap.pojo.filters.AttributeValueAssertionFilterPOJO;
+import org.apache.asn1.ldap.pojo.filters.NotFilterPOJO;
+import org.apache.asn1.ldap.pojo.filters.OrFilterPOJO;
+import org.apache.log4j.Logger;
+import org.apache.log4j.PropertyConfigurator;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+/**
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class SearchRequestTest extends TestCase {
+ /** Logger */
+ private static Logger log = Logger.getLogger( SearchRequestTest.class );
+
+ static
+ {
+ PropertyConfigurator.configure( "conf/log4j.conf" );
+ }
+
+ /**
+ * Test the decoding of a SearchRequest with no controls.
+ * The search filter is :
+ * (&(|(objectclass=top)(ou=contacts))(!(objectclass=ttt)))
+ */
+ public void testDecodeSearchRequestNoControls()
+ {
+ Asn1Decoder ldapDecoder = new LdapDecoder();
+
+ ByteBuffer stream = ByteBuffer.allocate( 0x77 );
+ stream.put(
+ new byte[]
+ {
+ 0x30, 0x75, // LDAPMessage ::=SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ 0x63, 0x70, // CHOICE { ..., searchRequest SearchRequest, ...
+ // SearchRequest ::= APPLICATION[3] SEQUENCE {
+ 0x04, 0x1F, // baseObject LDAPDN,
+ '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, // scope ENUMERATED {
+ // baseObject (0),
+ // singleLevel (1),
+ // wholeSubtree (2) },
+ 0x0A, 0x01, 0x03, // derefAliases ENUMERATED {
+ // neverDerefAliases (0),
+ // derefInSearching (1),
+ // derefFindingBaseObj (2),
+ // derefAlways (3) },
+ // sizeLimit INTEGER (0 .. maxInt), (1000)
+ 0x02, 0x02, 0x03, (byte)0xE8,
+ // timeLimit INTEGER (0 .. maxInt), (1000)
+ 0x02, 0x02, 0x03, (byte)0xE8,
+ 0x01, 0x01, 0x3E, // typesOnly BOOLEAN, (TRUE)
+ // filter Filter,
+ (byte)0xA0, 0x3C, // Filter ::= CHOICE {
+ // and [0] SET OF Filter,
+ (byte)0xA1, 0x24, // or [1] SET of Filter,
+ (byte)0xA3, 0x12, // equalityMatch [3] AttributeValueAssertion,
+ // AttributeValueAssertion ::= SEQUENCE {
+ // attributeDesc AttributeDescription (LDAPString),
+ 0x04, 0x0B, 'o', 'b', 'j', 'e', 'c', 't', 'c', 'l', 'a', 's', 's',
+ // assertionValue AssertionValue (OCTET STRING) }
+ 0x04, 0x03, 't', 'o', 'p',
+ (byte)0xA3, 0x0E, // equalityMatch [3] AttributeValueAssertion,
+ // AttributeValueAssertion ::= SEQUENCE {
+ 0x04, 0x02, 'o', 'u', // attributeDesc AttributeDescription (LDAPString),
+ // assertionValue AssertionValue (OCTET STRING) }
+ 0x04, 0x08, 'c', 'o', 'n', 't', 'a', 'c', 't', 's',
+ (byte)0xA2, 0x14, // not [2] Filter,
+ (byte)0xA3, 0x12, // equalityMatch [3] AttributeValueAssertion,
+ // AttributeValueAssertion ::= SEQUENCE {
+ // 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'
+ } );
+
+ stream.flip();
+
+ // Allocate a BindRequest Container
+ IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+ try
+ {
+ ldapDecoder.decode( stream, ldapMessageContainer );
+ }
+ catch ( DecoderException de )
+ {
+ de.printStackTrace();
+ Assert.fail( de.getMessage() );
+ }
+
+ LdapMessagePOJO message = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
+ SearchRequestPOJO sr = ( SearchRequestPOJO ) ( message.getProtocolOp() );
+
+ Assert.assertEquals( 1, message.getMessageId() );
+ Assert.assertEquals( "uid=akarasulu,dc=example,dc=com", sr.getBaseObject().toString() );
+ Assert.assertEquals( LdapConstants.SCOPE_SINGLE_LEVEL, sr.getScope() );
+ Assert.assertEquals( LdapConstants.DEREF_ALWAYS, sr.getDerefAliases() );
+ Assert.assertEquals( 1000, sr.getSizeLimit() );
+ Assert.assertEquals( 1000, sr.getTimeLimit() );
+ Assert.assertEquals( true, sr.isTypesOnly() );
+
+ // (& (...
+ AndFilterPOJO andFilter = (AndFilterPOJO)sr.getFilter();
+ Assert.assertNotNull(andFilter);
+
+ ArrayList andFilters = andFilter.getAndFilter();
+
+ // (& (| (...
+ Assert.assertEquals(2, andFilters.size());
+ OrFilterPOJO orFilter = (OrFilterPOJO)andFilters.get(0);
+ Assert.assertNotNull(orFilter);
+
+ // (& (| (obectclass=top) (...
+ ArrayList orFilters = orFilter.getOrFilter();
+ Assert.assertEquals(2, orFilters.size());
+ AttributeValueAssertionFilterPOJO equalityMatch = (AttributeValueAssertionFilterPOJO)orFilters.get(0);
+ Assert.assertNotNull(equalityMatch);
+
+ AttributeValueAssertionPOJO assertion = equalityMatch.getAssertion();
+ Assert.assertNotNull(assertion);
+
+ Assert.assertEquals("objectclass", assertion.getAttributeDesc().toString());
+ Assert.assertEquals("[74][6F][70]", assertion.getAssertionValue().toString());
+
+ // (& (| (objectclass=top) (ou=contacts) ) (...
+ equalityMatch = (AttributeValueAssertionFilterPOJO)orFilters.get(1);
+ Assert.assertNotNull(equalityMatch);
+
+ assertion = equalityMatch.getAssertion();
+ Assert.assertNotNull(assertion);
+
+ Assert.assertEquals("ou", assertion.getAttributeDesc().toString());
+ Assert.assertEquals("[63][6F][6E][74][61][63][74][73]", assertion.getAssertionValue().toString());
+
+ // (& (| (objectclass=top) (ou=contacts) ) (! ...
+ NotFilterPOJO notFilter = (NotFilterPOJO)andFilters.get(1);
+ Assert.assertNotNull(notFilter);
+
+ // (& (| (objectclass=top) (ou=contacts) ) (! (objectclass=ttt) ) )
+ equalityMatch = (AttributeValueAssertionFilterPOJO)notFilter.getNotFilter();
+ Assert.assertNotNull(equalityMatch);
+
+ assertion = equalityMatch.getAssertion();
+ Assert.assertNotNull(assertion);
+
+ Assert.assertEquals("objectclass", assertion.getAttributeDesc().toString());
+ Assert.assertEquals("[74][74][74]", assertion.getAssertionValue().toString());
+ }
+
+ /**
+ * Test the decoding of a SearchRequest with no controls
+ */
+/* public void testDecodeSearchRequestSimpleNoControls()
+ {
+ Asn1Decoder ldapDecoder = new LdapDecoder();
+
+ ByteBuffer stream = ByteBuffer.allocate( 0x8F );
+ stream.put(
+ new byte[]
+ {
+ 0x30, (byte)0x81, (byte)0x8C, // LDAPMessage ::=SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ 0x63, (byte)0x81, (byte)0x86, // CHOICE { ..., searchRequest SearchRequest, ...
+ // SearchRequest ::= APPLICATION[3] SEQUENCE {
+ 0x04, 0x1F, // baseObject LDAPDN,
+ '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, // scope ENUMERATED {
+ // baseObject (0),
+ // singleLevel (1),
+ // wholeSubtree (2) },
+ 0x0A, 0x01, 0x03, // derefAliases ENUMERATED {
+ // neverDerefAliases (0),
+ // derefInSearching (1),
+ // derefFindingBaseObj (2),
+ // derefAlways (3) },
+ // sizeLimit INTEGER (0 .. maxInt), (1000)
+ 0x02, 0x02, 0x03, (byte)0xE8,
+ // timeLimit INTEGER (0 .. maxInt), (1000)
+ 0x02, 0x02, 0x03, (byte)0xE8,
+ 0x01, 0x01, 0x3E, // typesOnly BOOLEAN, (TRUE)
+ // filter Filter,
+ (byte)0xA0, 0x52, // Filter ::= CHOICE {
+ // and [0] SET OF Filter,
+ (byte)0xA1, 0x24, // or [1] SET of Filter,
+ (byte)0xA3, 0x12, // equalityMatch [3] AttributeValueAssertion,
+ // AttributeValueAssertion ::= SEQUENCE {
+ // attributeDesc AttributeDescription (LDAPString),
+ 0x04, 0x0B, 'o', 'b', 'j', 'e', 'c', 't', 'c', 'l', 'a', 's', 's',
+ // assertionValue AssertionValue (OCTET STRING) }
+ 0x04, 0x03, 't', 'o', 'p',
+ (byte)0xA3, 0x0E, // equalityMatch [3] AttributeValueAssertion,
+ // AttributeValueAssertion ::= SEQUENCE {
+ 0x04, 0x02, 'o', 'u', // attributeDesc AttributeDescription (LDAPString),
+ // assertionValue AssertionValue (OCTET STRING) }
+ 0x04, 0x08, 'c', 'o', 'n', 't', 'a', 'c', 't', 's',
+ (byte)0xA2, 0x14, // not [2] Filter,
+ (byte)0xA3, 0x12, // equalityMatch [3] AttributeValueAssertion,
+ // AttributeValueAssertion ::= SEQUENCE {
+ // 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',
+ (byte)0xA4, 0x14, // substrings [4] SubstringFilter,
+ // SubstringFilter ::= SEQUENCE {
+ // type AttributeDescription (LDAPString),
+ 0x04, 0x0B, 'o', 'b', 'j', 'e', 'c', 't', 'c', 'l', 'a', 's', 's',
+ 0x30, 0x05, // substrings SEQUENCE OF CHOICE {
+ // ...
+ // final [2] LDAPString } }
+ (byte)0x82, 0x03, 't', 'o', 'p'
+
+ } );
+
+ stream.flip();
+
+ // Allocate a BindRequest Container
+ IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+ try
+ {
+ ldapDecoder.decode( stream, ldapMessageContainer );
+ }
+ catch ( DecoderException de )
+ {
+ de.printStackTrace();
+ Assert.fail( de.getMessage() );
+ }
+
+ LdapMessagePOJO message = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
+ SearchRequestPOJO sr = ( SearchRequestPOJO ) ( message.getProtocolOp() );
+
+ Assert.assertEquals( 1, message.getMessageId() );
+ Assert.assertEquals( "uid=akarasulu,dc=example,dc=com", sr.getBaseObject().toString() );
+ Assert.assertEquals( LdapConstants.SCOPE_SINGLE_LEVEL, sr.getScope() );
+ Assert.assertEquals( LdapConstants.DEREF_ALWAYS, sr.getDerefAliases() );
+ Assert.assertEquals( 1000, sr.getSizeLimit() );
+ Assert.assertEquals( 1000, sr.getTimeLimit() );
+ Assert.assertEquals( true, sr.isTypesOnly() );
+ }*/
+}