Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 300 invoked from network); 27 Aug 2006 00:13:56 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 27 Aug 2006 00:13:56 -0000 Received: (qmail 21452 invoked by uid 500); 27 Aug 2006 00:13:55 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 21408 invoked by uid 500); 27 Aug 2006 00:13:55 -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 21397 invoked by uid 99); 27 Aug 2006 00:13:55 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 26 Aug 2006 17:13:55 -0700 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy) Received: from [140.211.166.113] (HELO eris.apache.org) (140.211.166.113) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 26 Aug 2006 17:13:54 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id 59C9D1A981A; Sat, 26 Aug 2006 17:13:34 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r437255 - in /directory/branches/apacheds/1.0: core-unit/src/test/java/org/apache/directory/server/core/jndi/ core/src/main/java/org/apache/directory/server/core/partition/impl/btree/ server-unit/src/test/java/org/apache/directory/server/ Date: Sun, 27 Aug 2006 00:13:33 -0000 To: commits@directory.apache.org From: akarasulu@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20060827001334.59C9D1A981A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: akarasulu Date: Sat Aug 26 17:13:31 2006 New Revision: 437255 URL: http://svn.apache.org/viewvc?rev=437255&view=rev Log: partial fix for DIRSERVER-169 and test case for DIRSERVER-715 Added: directory/branches/apacheds/1.0/core-unit/src/test/java/org/apache/directory/server/core/jndi/DIRSERVER169ITest.java directory/branches/apacheds/1.0/server-unit/src/test/java/org/apache/directory/server/BinarySearchTest.java Modified: directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/BTreeSearchResultEnumeration.java Added: directory/branches/apacheds/1.0/core-unit/src/test/java/org/apache/directory/server/core/jndi/DIRSERVER169ITest.java URL: http://svn.apache.org/viewvc/directory/branches/apacheds/1.0/core-unit/src/test/java/org/apache/directory/server/core/jndi/DIRSERVER169ITest.java?rev=437255&view=auto ============================================================================== --- directory/branches/apacheds/1.0/core-unit/src/test/java/org/apache/directory/server/core/jndi/DIRSERVER169ITest.java (added) +++ directory/branches/apacheds/1.0/core-unit/src/test/java/org/apache/directory/server/core/jndi/DIRSERVER169ITest.java Sat Aug 26 17:13:31 2006 @@ -0,0 +1,133 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.directory.server.core.jndi; + + +import org.apache.directory.server.core.unit.AbstractAdminTestCase; +import org.apache.directory.server.core.jndi.CoreContextFactory; + +import javax.naming.directory.Attributes; +import javax.naming.directory.BasicAttributes; +import javax.naming.directory.Attribute; +import javax.naming.directory.BasicAttribute; +import javax.naming.directory.SearchResult; +import javax.naming.directory.SearchControls; +import javax.naming.directory.DirContext; +import javax.naming.directory.InitialDirContext; +import javax.naming.NamingEnumeration; +import javax.naming.Context; +import java.util.Hashtable; + + +/** + * Contributed by Luke Taylor to fix DIRSERVER-169. + * + * @author Apache Directory Project + * @version $Rev$ + */ +public class DIRSERVER169ITest extends AbstractAdminTestCase +{ + protected void setUp() throws Exception + { + super.setUp(); + Attributes people = new BasicAttributes( true ); + Attribute attribute = new BasicAttribute( "objectClass" ); + attribute.add( "top" ); + attribute.add( "organizationalUnit" ); + people.put( attribute ); + people.put( "ou", "people" ); + sysRoot.createSubcontext( "ou=people", people ); + + Attributes user = new BasicAttributes( "uid", "bob" ); + user.put( "cn", "Bob Hamilton" ); + user.put( "userPassword", "bobspassword".getBytes( "UTF-8" ) ); + + Attribute objectClass = new BasicAttribute( "objectClass" ); + user.put( objectClass ); + objectClass.add( "top" ); + objectClass.add( "person" ); + objectClass.add( "organizationalPerson" ); + objectClass.add( "inetOrgPerson" ); + user.put( "sn", "Hamilton" ); + + sysRoot.createSubcontext( "uid=bob,ou=people", user ); + System.out.println( sysRoot.getNameInNamespace() ); + } + + + public void testSearchResultNameIsRelativeToSearchContext() throws Exception + { + Hashtable env = configuration.toJndiEnvironment(); + env.put( Context.INITIAL_CONTEXT_FACTORY, CoreContextFactory.class.getName() ); + env.put( Context.PROVIDER_URL, "ou=system" ); + + DirContext ctx = new InitialDirContext( env ); + SearchControls ctls = new SearchControls(); + String searchBase = "ou=people"; + + NamingEnumeration results = ctx.search( searchBase, "(uid=bob)", ctls ); + assertTrue( results.hasMore() ); + SearchResult searchResult = ( SearchResult ) results.next(); + + StringBuffer userDn = new StringBuffer(); + userDn.append( searchResult.getName() ); + + // Note that only if it's returned as a relative name do you need to + // add the search base to the returned name value + if ( searchResult.isRelative() ) + { + if ( searchBase.length() > 0 ) + { + userDn.append( "," ); + userDn.append( searchBase ); + } + userDn.append( "," ); + userDn.append( ctx.getNameInNamespace() ); + } + + assertEquals( "uid=bob,ou=people," + sysRoot.getNameInNamespace(), userDn.toString() ); + } + + + /** + * TODO re-enable this test after fixing binary attribute searches. + * @throws Exception + */ + public void testPasswordComparisonSucceeds() throws Exception + { + /* + Hashtable env = configuration.toJndiEnvironment(); + env.put( Context.INITIAL_CONTEXT_FACTORY, CoreContextFactory.class.getName() ); + env.put( Context.PROVIDER_URL, "ou=system" ); + + DirContext ctx = new InitialDirContext( env ); + SearchControls ctls = new SearchControls(); + ctls.setReturningAttributes( new String[0] ); + ctls.setSearchScope( SearchControls.OBJECT_SCOPE ); + + String filter = "(userPassword={0})"; + NamingEnumeration results = ctx.search( "uid=bob,ou=people", filter, new Object[] + { "bobspassword".getBytes( "UTF-8" ) }, ctls ); + + // We should have a match + assertTrue( results.hasMore() ); + */ + } +} Modified: directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/BTreeSearchResultEnumeration.java URL: http://svn.apache.org/viewvc/directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/BTreeSearchResultEnumeration.java?rev=437255&r1=437254&r2=437255&view=diff ============================================================================== --- directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/BTreeSearchResultEnumeration.java (original) +++ directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/BTreeSearchResultEnumeration.java Sat Aug 26 17:13:31 2006 @@ -206,7 +206,9 @@ } } - return new BTreeSearchResult( rec.getEntryId(), name, null, entry ); + BTreeSearchResult result = new BTreeSearchResult( rec.getEntryId(), name, null, entry ); + result.setRelative( false ); + return result; } Added: directory/branches/apacheds/1.0/server-unit/src/test/java/org/apache/directory/server/BinarySearchTest.java URL: http://svn.apache.org/viewvc/directory/branches/apacheds/1.0/server-unit/src/test/java/org/apache/directory/server/BinarySearchTest.java?rev=437255&view=auto ============================================================================== --- directory/branches/apacheds/1.0/server-unit/src/test/java/org/apache/directory/server/BinarySearchTest.java (added) +++ directory/branches/apacheds/1.0/server-unit/src/test/java/org/apache/directory/server/BinarySearchTest.java Sat Aug 26 17:13:31 2006 @@ -0,0 +1,124 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.directory.server; + + +import java.util.Hashtable; + +import javax.naming.NamingEnumeration; +import javax.naming.directory.Attribute; +import javax.naming.directory.Attributes; +import javax.naming.directory.BasicAttribute; +import javax.naming.directory.BasicAttributes; +import javax.naming.directory.SearchControls; +import javax.naming.directory.SearchResult; +import javax.naming.ldap.InitialLdapContext; +import javax.naming.ldap.LdapContext; + +import org.apache.directory.server.unit.AbstractServerTest; + + +/** + * For DIRSERVER-715 and part of DIRSERVER-169. May include other tests + * for binary attribute based searching. + * + * @author Apache Directory Project + * @version $Rev$ + */ +public class BinarySearchTest extends AbstractServerTest +{ + private LdapContext ctx = null; + + + /** + * Creation of required attributes of a person entry. + */ + protected Attributes getPersonAttributes( String sn, String cn ) + { + Attributes attributes = new BasicAttributes(); + Attribute attribute = new BasicAttribute( "objectClass" ); + attribute.add( "top" ); + attribute.add( "person" ); + attributes.put( attribute ); + attributes.put( "cn", cn ); + attributes.put( "sn", sn ); + + return attributes; + } + + + /** + * Create context and a person entry. + */ + public void setUp() throws Exception + { + super.setUp(); + + Hashtable env = new Hashtable(); + env.put( "java.naming.factory.initial", "com.sun.jndi.ldap.LdapCtxFactory" ); + env.put( "java.naming.provider.url", "ldap://localhost:" + port + "/ou=system" ); + env.put( "java.naming.security.principal", "uid=admin,ou=system" ); + env.put( "java.naming.security.credentials", "secret" ); + env.put( "java.naming.security.authentication", "simple" ); + + ctx = new InitialLdapContext( env, null ); + assertNotNull( ctx ); + } + + + /** + * Remove person entry and close context. + */ + public void tearDown() throws Exception + { + ctx.close(); + ctx = null; + super.tearDown(); + } + + + /** + * TODO re-enable this test after fixing binary attribute searches. + * + * @throws Exception + */ + public void testSearchByBinaryAttribute() throws Exception + { + byte[] certData = new byte[] { 0x34, 0x56, 0x4e, 0x5f }; + + // First let's add a some binary data representing a userCertificate + Attributes attrs = getPersonAttributes( "Bush", "Kate Bush" ); + attrs.put( "userCertificate", certData ); + ctx.createSubcontext( "cn=Kate Bush", attrs ); + + // Search for kate by cn first + SearchControls controls = new SearchControls(); + controls.setSearchScope( SearchControls.ONELEVEL_SCOPE ); + NamingEnumeration enm = ctx.search( "", "(cn=Kate Bush)", controls ); + assertTrue( enm.hasMore() ); + SearchResult sr = ( SearchResult ) enm.next(); + assertNotNull( sr ); + assertFalse( enm.hasMore() ); + assertEquals( "cn=Kate Bush", sr.getName() ); + + +// enm = ctx.search( "", "(userCertificate={0})", new Object[] {certData}, controls ); + } +}