From commits-return-4899-apmail-directory-commits-archive=directory.apache.org@directory.apache.org Mon Jun 06 22:39:18 2005 Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 6809 invoked from network); 6 Jun 2005 22:39:18 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 6 Jun 2005 22:39:18 -0000 Received: (qmail 45093 invoked by uid 500); 6 Jun 2005 22:39:17 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 45063 invoked by uid 500); 6 Jun 2005 22:39:17 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 45049 invoked by uid 99); 6 Jun 2005 22:39:17 -0000 X-ASF-Spam-Status: No, hits=-9.8 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from minotaur.apache.org (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.28) with SMTP; Mon, 06 Jun 2005 15:39:12 -0700 Received: (qmail 6722 invoked by uid 65534); 6 Jun 2005 22:39:05 -0000 Message-ID: <20050606223905.6721.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: svn commit: r185081 - /directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/SearchRequestTest.java Date: Mon, 06 Jun 2005 22:39:05 -0000 To: commits@directory.apache.org From: elecharny@apache.org X-Mailer: svnmailer-1.0.0-dev X-Virus-Checked: Checked X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: elecharny Date: Mon Jun 6 15:39:04 2005 New Revision: 185081 URL: http://svn.apache.org/viewcvs?rev=3D185081&view=3Drev Log: Added the FIRST working test case for a searchRequest message ! Lot of swea= t and work... At least, it correctly decode a partial request.=20 Not finished yet. (The PDU is incorrect, it lacks the attributes descriptio= ns at the end...) Added: directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/co= dec/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/s= rc/test/org/apache/asn1/ldap/codec/SearchRequestTest.java?rev=3D185081&view= =3Dauto =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/co= dec/SearchRequestTest.java (added) +++ directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/co= dec/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 impli= ed. + * 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 Apache Directory Pr= oject + */ +public class SearchRequestTest extends TestCase { + /** Logger */ + private static Logger log =3D Logger.getLogger( SearchRequestTest.clas= s ); + + static + { + PropertyConfigurator.configure( "conf/log4j.conf" ); + } + + /** + * Test the decoding of a SearchRequest with no controls. + * The search filter is :=20 + * (&(|(objectclass=3Dtop)(ou=3Dcontacts))(!(objectclass=3Dttt))) + */ + public void testDecodeSearchRequestNoControls() + { + Asn1Decoder ldapDecoder =3D new LdapDecoder(); + + ByteBuffer stream =3D ByteBuffer.allocate( 0x77 ); + stream.put( + new byte[] + { + 0x30, 0x75, // LDAPMessage ::=3DSEQUENCE { + 0x02, 0x01, 0x01, // messageID MessageID + 0x63, 0x70, // CHOICE { ..., searchRequest SearchRe= quest, ... + // SearchRequest ::=3D APPLICATION[3] SEQU= ENCE { + 0x04, 0x1F, // baseObject LDAPDN, + 'u', 'i', 'd', '=3D', 'a', 'k', 'a', 'r', 'a', 's', 'u', 'l', 'u', ','= , 'd', 'c', '=3D', + 'e', 'x', 'a', 'm', 'p', 'l', 'e', ',', 'd', 'c', '=3D', '= 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 ::=3D CHOICE { + // and [0] SET OF Filter, + (byte)0xA1, 0x24, // or [1] SET of Filter, + (byte)0xA3, 0x12, // equalityMatch [3] AttributeValueAsser= tion, + // AttributeValueAssertion ::=3D 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] AttributeValueAsser= tion, + // AttributeValueAssertion ::=3D SEQUENCE { + 0x04, 0x02, 'o', 'u', // attributeDesc AttributeDescription (L= DAPString), + // assertionValue AssertionValue (OCTE= T STRING) } + 0x04, 0x08, 'c', 'o', 'n', 't', 'a', 'c', 't', 's', + (byte)0xA2, 0x14, // not [2] Filter, + (byte)0xA3, 0x12, // equalityMatch [3] AttributeValueAsser= tion, + // AttributeValueAssertion ::=3D SEQUENCE { + // attributeDesc AttributeDescriptio= n (LDAPString), + 0x04, 0x0B, 'o', 'b', 'j', 'e', 'c', 't', 'c', 'l', 'a', '= s', 's', + // assertionValue AssertionValue (OCTE= T STRING) } + 0x04, 0x03, 't', 't', 't' + } ); + + stream.flip(); + + // Allocate a BindRequest Container + IAsn1Container ldapMessageContainer =3D new LdapMessageContainer(); + + try + { + ldapDecoder.decode( stream, ldapMessageContainer ); + } + catch ( DecoderException de ) + { + de.printStackTrace(); + Assert.fail( de.getMessage() ); + } + =09 + LdapMessagePOJO message =3D ( ( LdapMessageContainer ) ldapMessage= Container ).getLdapMessage(); + SearchRequestPOJO sr =3D ( SearchRequestPOJO ) ( message.getP= rotocolOp() ); + + Assert.assertEquals( 1, message.getMessageId() ); + Assert.assertEquals( "uid=3Dakarasulu,dc=3Dexample,dc=3Dcom", sr.g= etBaseObject().toString() ); + Assert.assertEquals( LdapConstants.SCOPE_SINGLE_LEVEL, sr.getScope= () ); + Assert.assertEquals( LdapConstants.DEREF_ALWAYS, sr.getDerefAliase= s() ); + Assert.assertEquals( 1000, sr.getSizeLimit() ); + Assert.assertEquals( 1000, sr.getTimeLimit() ); + Assert.assertEquals( true, sr.isTypesOnly() ); + =20 + // (& (... + AndFilterPOJO andFilter =3D (AndFilterPOJO)sr.getFilter(); + Assert.assertNotNull(andFilter); + =20 + ArrayList andFilters =3D andFilter.getAndFilter(); + =20 + // (& (| (... + Assert.assertEquals(2, andFilters.size()); + OrFilterPOJO orFilter =3D (OrFilterPOJO)andFilters.get(0); + Assert.assertNotNull(orFilter); + =20 + // (& (| (obectclass=3Dtop) (... + ArrayList orFilters =3D orFilter.getOrFilter(); + Assert.assertEquals(2, orFilters.size()); + AttributeValueAssertionFilterPOJO equalityMatch =3D (AttributeValu= eAssertionFilterPOJO)orFilters.get(0); =20 + Assert.assertNotNull(equalityMatch); + =20 + AttributeValueAssertionPOJO assertion =3D equalityMatch.getAsserti= on(); + Assert.assertNotNull(assertion); + =20 + Assert.assertEquals("objectclass", assertion.getAttributeDesc().to= String()); + Assert.assertEquals("[74][6F][70]", assertion.getAssertionValue().= toString()); + =20 + // (& (| (objectclass=3Dtop) (ou=3Dcontacts) ) (... + equalityMatch =3D (AttributeValueAssertionFilterPOJO)orFilters.get= (1); =20 + Assert.assertNotNull(equalityMatch); + =20 + assertion =3D equalityMatch.getAssertion(); + Assert.assertNotNull(assertion); + =20 + Assert.assertEquals("ou", assertion.getAttributeDesc().toString()); + Assert.assertEquals("[63][6F][6E][74][61][63][74][73]", assertion.= getAssertionValue().toString()); + =20 + // (& (| (objectclass=3Dtop) (ou=3Dcontacts) ) (! ... + NotFilterPOJO notFilter =3D (NotFilterPOJO)andFilters.get(1); + Assert.assertNotNull(notFilter); + =20 + // (& (| (objectclass=3Dtop) (ou=3Dcontacts) ) (! (objectclass=3Dt= tt) ) ) + equalityMatch =3D (AttributeValueAssertionFilterPOJO)notFilter.get= NotFilter(); =20 + Assert.assertNotNull(equalityMatch); + =20 + assertion =3D equalityMatch.getAssertion(); + Assert.assertNotNull(assertion); + =20 + Assert.assertEquals("objectclass", assertion.getAttributeDesc().to= String()); + Assert.assertEquals("[74][74][74]", assertion.getAssertionValue().= toString()); + } + + /** + * Test the decoding of a SearchRequest with no controls + */ +/* public void testDecodeSearchRequestSimpleNoControls() + { + Asn1Decoder ldapDecoder =3D new LdapDecoder(); + + ByteBuffer stream =3D ByteBuffer.allocate( 0x8F ); + stream.put( + new byte[] + { + 0x30, (byte)0x81, (byte)0x8C, // LDAPMessage ::=3DSEQUENC= E { + 0x02, 0x01, 0x01, // messageID MessageID + 0x63, (byte)0x81, (byte)0x86, // CHOICE { ..., searchRequest Se= archRequest, ... + // SearchRequest ::=3D APPLICATION[3] SEQU= ENCE { + 0x04, 0x1F, // baseObject LDAPDN, + 'u', 'i', 'd', '=3D', 'a', 'k', 'a', 'r', 'a', 's', 'u', 'l', 'u', ','= , 'd', 'c', '=3D', + 'e', 'x', 'a', 'm', 'p', 'l', 'e', ',', 'd', 'c', '=3D', '= 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 ::=3D CHOICE { + // and [0] SET OF Filter, + (byte)0xA1, 0x24, // or [1] SET of Filter, + (byte)0xA3, 0x12, // equalityMatch [3] AttributeValueAsser= tion, + // AttributeValueAssertion ::=3D 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] AttributeValueAsser= tion, + // AttributeValueAssertion ::=3D SEQUENCE { + 0x04, 0x02, 'o', 'u', // attributeDesc AttributeDescription (L= DAPString), + // assertionValue AssertionValue (OCTE= T STRING) } + 0x04, 0x08, 'c', 'o', 'n', 't', 'a', 'c', 't', 's', + (byte)0xA2, 0x14, // not [2] Filter, + (byte)0xA3, 0x12, // equalityMatch [3] AttributeValueAsser= tion, + // AttributeValueAssertion ::=3D SEQUENCE { + // attributeDesc AttributeDescriptio= n (LDAPString), + 0x04, 0x0B, 'o', 'b', 'j', 'e', 'c', 't', 'c', 'l', 'a', '= s', 's', + // assertionValue AssertionValue (OCTE= T STRING) } + 0x04, 0x03, 't', 't', 't', + (byte)0xA4, 0x14, // substrings [4] SubstringFilter, + // SubstringFilter ::=3D SEQUENCE { + // type AttributeDescription (L= DAPString), + 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' + =09 + } ); + + stream.flip(); + + // Allocate a BindRequest Container + IAsn1Container ldapMessageContainer =3D new LdapMessageContainer(); + + try + { + ldapDecoder.decode( stream, ldapMessageContainer ); + } + catch ( DecoderException de ) + { + de.printStackTrace(); + Assert.fail( de.getMessage() ); + } + =09 + LdapMessagePOJO message =3D ( ( LdapMessageContainer ) ldapMessage= Container ).getLdapMessage(); + SearchRequestPOJO sr =3D ( SearchRequestPOJO ) ( message.getP= rotocolOp() ); + + Assert.assertEquals( 1, message.getMessageId() ); + Assert.assertEquals( "uid=3Dakarasulu,dc=3Dexample,dc=3Dcom", sr.g= etBaseObject().toString() ); + Assert.assertEquals( LdapConstants.SCOPE_SINGLE_LEVEL, sr.getScope= () ); + Assert.assertEquals( LdapConstants.DEREF_ALWAYS, sr.getDerefAliase= s() ); + Assert.assertEquals( 1000, sr.getSizeLimit() ); + Assert.assertEquals( 1000, sr.getTimeLimit() ); + Assert.assertEquals( true, sr.isTypesOnly() ); + }*/ +}