You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by ak...@apache.org on 2006/08/27 02:13:33 UTC
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/
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 <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @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 <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @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 );
+ }
+}