Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 53269 invoked from network); 18 Aug 2008 21:29:58 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 18 Aug 2008 21:29:58 -0000 Received: (qmail 2388 invoked by uid 500); 18 Aug 2008 21:29:57 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 2350 invoked by uid 500); 18 Aug 2008 21:29:57 -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 2341 invoked by uid 99); 18 Aug 2008 21:29:56 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 18 Aug 2008 14:29:56 -0700 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 18 Aug 2008 21:29:08 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id AFBB72388873; Mon, 18 Aug 2008 14:29:07 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r686871 - /directory/apacheds/branches/bigbang/server-integ/src/test/java/org/apache/directory/server/operations/modify/ModifyReplaceIT.java Date: Mon, 18 Aug 2008 21:29:07 -0000 To: commits@directory.apache.org From: elecharny@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080818212907.AFBB72388873@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: elecharny Date: Mon Aug 18 14:29:06 2008 New Revision: 686871 URL: http://svn.apache.org/viewvc?rev=686871&view=rev Log: Added some test for a special case : a replacement of an attribute which is indexed and not part of the initial entry (this has been fixed by Kiran) Modified: directory/apacheds/branches/bigbang/server-integ/src/test/java/org/apache/directory/server/operations/modify/ModifyReplaceIT.java Modified: directory/apacheds/branches/bigbang/server-integ/src/test/java/org/apache/directory/server/operations/modify/ModifyReplaceIT.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/server-integ/src/test/java/org/apache/directory/server/operations/modify/ModifyReplaceIT.java?rev=686871&r1=686870&r2=686871&view=diff ============================================================================== --- directory/apacheds/branches/bigbang/server-integ/src/test/java/org/apache/directory/server/operations/modify/ModifyReplaceIT.java (original) +++ directory/apacheds/branches/bigbang/server-integ/src/test/java/org/apache/directory/server/operations/modify/ModifyReplaceIT.java Mon Aug 18 14:29:06 2008 @@ -20,22 +20,50 @@ package org.apache.directory.server.operations.modify; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + 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.DirContext; import javax.naming.directory.ModificationItem; import javax.naming.directory.SearchControls; import javax.naming.directory.SearchResult; +import org.apache.directory.server.core.DefaultDirectoryService; +import org.apache.directory.server.core.DirectoryService; +import org.apache.directory.server.core.entry.DefaultServerEntry; +import org.apache.directory.server.core.entry.ServerEntry; +import org.apache.directory.server.core.integ.IntegrationUtils; import org.apache.directory.server.core.integ.Level; +import org.apache.directory.server.core.integ.annotations.ApplyLdifs; import org.apache.directory.server.core.integ.annotations.CleanupLevel; +import org.apache.directory.server.core.integ.annotations.Factory; +import org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmIndex; +import org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmPartition; +import org.apache.directory.server.integ.LdapServerFactory; import org.apache.directory.server.integ.SiRunner; import static org.apache.directory.server.integ.ServerIntegrationUtils.getWiredContext; import org.apache.directory.server.newldap.LdapServer; +import org.apache.directory.server.newldap.handlers.bind.MechanismHandler; +import org.apache.directory.server.newldap.handlers.bind.SimpleMechanismHandler; +import org.apache.directory.server.newldap.handlers.bind.cramMD5.CramMd5MechanismHandler; +import org.apache.directory.server.newldap.handlers.bind.digestMD5.DigestMd5MechanismHandler; +import org.apache.directory.server.newldap.handlers.bind.gssapi.GssapiMechanismHandler; +import org.apache.directory.server.newldap.handlers.bind.ntlm.NtlmMechanismHandler; +import org.apache.directory.server.newldap.handlers.extended.StartTlsHandler; +import org.apache.directory.server.newldap.handlers.extended.StoredProcedureExtendedOperationHandler; +import org.apache.directory.server.protocol.shared.SocketAcceptor; +import org.apache.directory.server.xdbm.Index; +import org.apache.directory.shared.ldap.constants.SchemaConstants; +import org.apache.directory.shared.ldap.constants.SupportedSaslMechanisms; +import org.apache.directory.shared.ldap.name.LdapDN; +import org.apache.directory.shared.ldap.util.DateUtils; +import org.apache.mina.util.AvailablePortFinder; import org.junit.Test; import org.junit.runner.RunWith; import static org.junit.Assert.assertTrue; @@ -50,6 +78,24 @@ */ @RunWith ( SiRunner.class ) @CleanupLevel ( Level.SUITE ) +@Factory ( ModifyReplaceIT.Factory.class ) +@ApplyLdifs( { + // Entry # 0 + "dn: cn=Kate Bush,ou=system\n" + + "objectClass: top\n" + + "objectClass: person\n" + + "sn: Bush\n" + + "cn: Kate Bush\n\n" + + // Entry # 1 + "dn: cn=Kim Wilde,ou=system\n" + + "objectClass: top\n" + + "objectClass: person\n" + + "objectClass: organizationalPerson \n" + + "objectClass: inetOrgPerson \n" + + "sn: Wilde\n" + + "cn: Kim Wilde\n\n" + } +) public class ModifyReplaceIT { private static final String BASE = "ou=system"; @@ -57,19 +103,74 @@ public static LdapServer ldapServer; - protected Attributes getPersonAttributes( String sn, String cn ) + public static class Factory implements LdapServerFactory { - Attributes attrs = new BasicAttributes(); - Attribute ocls = new BasicAttribute("objectClass"); - ocls.add("top"); - ocls.add("person"); - attrs.put(ocls); - attrs.put("cn", cn); - attrs.put("sn", sn); + public LdapServer newInstance() throws Exception + { + DirectoryService service = new DefaultDirectoryService(); + IntegrationUtils.doDelete( service.getWorkingDirectory() ); + service.getChangeLog().setEnabled( true ); + service.setShutdownHookEnabled( false ); + + JdbmPartition system = new JdbmPartition(); + system.setId( "system" ); + + // @TODO need to make this configurable for the system partition + system.setCacheSize( 500 ); + + system.setSuffix( "ou=system" ); + + // Add indexed attributes for system partition + Set> indexedAttrs = new HashSet>(); + indexedAttrs.add( new JdbmIndex( SchemaConstants.OBJECT_CLASS_AT ) ); + indexedAttrs.add( new JdbmIndex( SchemaConstants.OU_AT ) ); + system.setIndexedAttributes( indexedAttrs ); + + // Add context entry for system partition + LdapDN systemDn = new LdapDN( "ou=system" ); + ServerEntry systemEntry = new DefaultServerEntry( service.getRegistries(), systemDn ); + systemEntry.put( "objectClass", "top", "organizationalUnit", "extensibleObject", "account" ); + systemEntry.put( SchemaConstants.CREATORS_NAME_AT, "uid=admin, ou=system" ); + systemEntry.put( SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime() ); + systemEntry.put( "ou", "system" ); + systemEntry.put( "uid", "testUid" ); + system.setContextEntry( systemEntry ); + service.setSystemPartition( system ); + + // change the working directory to something that is unique + // on the system and somewhere either under target directory + // or somewhere in a temp area of the machine. + + LdapServer ldapServer = new LdapServer(); + ldapServer.setDirectoryService( service ); + ldapServer.setSocketAcceptor( new SocketAcceptor( null ) ); + ldapServer.setIpPort( AvailablePortFinder.getNextAvailable( 1024 ) ); + ldapServer.addExtendedOperationHandler( new StartTlsHandler() ); + ldapServer.addExtendedOperationHandler( new StoredProcedureExtendedOperationHandler() ); + + // Setup SASL Mechanisms + + Map mechanismHandlerMap = new HashMap(); + mechanismHandlerMap.put( SupportedSaslMechanisms.PLAIN, new SimpleMechanismHandler() ); + + CramMd5MechanismHandler cramMd5MechanismHandler = new CramMd5MechanismHandler(); + mechanismHandlerMap.put( SupportedSaslMechanisms.CRAM_MD5, cramMd5MechanismHandler ); + + DigestMd5MechanismHandler digestMd5MechanismHandler = new DigestMd5MechanismHandler(); + mechanismHandlerMap.put( SupportedSaslMechanisms.DIGEST_MD5, digestMd5MechanismHandler ); + + GssapiMechanismHandler gssapiMechanismHandler = new GssapiMechanismHandler(); + mechanismHandlerMap.put( SupportedSaslMechanisms.GSSAPI, gssapiMechanismHandler ); + + NtlmMechanismHandler ntlmMechanismHandler = new NtlmMechanismHandler(); + mechanismHandlerMap.put( SupportedSaslMechanisms.NTLM, ntlmMechanismHandler ); + mechanismHandlerMap.put( SupportedSaslMechanisms.GSS_SPNEGO, ntlmMechanismHandler ); - return attrs; - } + ldapServer.setSaslMechanismHandlers( mechanismHandlerMap ); + return ldapServer; + } + } /** * Create a person entry and try to remove a not present attribute @@ -79,9 +180,7 @@ { DirContext sysRoot = ( DirContext ) getWiredContext( ldapServer ).lookup( BASE ); - Attributes attrs = getPersonAttributes( "Bush", "Kate Bush" ); String rdn = "cn=Kate Bush"; - sysRoot.createSubcontext( rdn, attrs ); Attribute attr = new BasicAttribute( "description" ); ModificationItem item = new ModificationItem( DirContext.REPLACE_ATTRIBUTE, attr ); @@ -97,7 +196,6 @@ while ( enm.hasMore() ) { SearchResult sr = ( SearchResult ) enm.next(); - attrs = sr.getAttributes(); Attribute cn = sr.getAttributes().get( "cn" ); assertNotNull( cn ); assertTrue( cn.contains("Kate Bush") ); @@ -115,9 +213,7 @@ { DirContext sysRoot = ( DirContext ) getWiredContext( ldapServer ).lookup( BASE ); - Attributes attrs = getPersonAttributes( "Bush", "Kate Bush" ); String rdn = "cn=Kate Bush"; - sysRoot.createSubcontext( rdn, attrs ); Attribute attr = new BasicAttribute( "numberOfOctaves" ); ModificationItem item = new ModificationItem( DirContext.REPLACE_ATTRIBUTE, attr ); @@ -133,7 +229,6 @@ while ( enm.hasMore() ) { SearchResult sr = enm.next(); - attrs = sr.getAttributes(); Attribute cn = sr.getAttributes().get( "cn" ); assertNotNull( cn ); assertTrue( cn.contains( "Kate Bush" ) ); @@ -151,9 +246,7 @@ { DirContext sysRoot = ( DirContext ) getWiredContext( ldapServer ).lookup( BASE ); - Attributes attrs = getPersonAttributes( "Bush", "Kate Bush" ); String rdn = "cn=Kate Bush"; - sysRoot.createSubcontext( rdn, attrs ); Attribute attr = new BasicAttribute( "numberOfOctaves" ); ModificationItem item = new ModificationItem( DirContext.REPLACE_ATTRIBUTE, attr ); @@ -171,7 +264,6 @@ while ( enm.hasMore() ) { SearchResult sr = enm.next(); - attrs = sr.getAttributes(); Attribute cn = sr.getAttributes().get( "cn" ); assertNotNull( cn ); assertTrue( cn.contains( "Kate Bush" ) ); @@ -179,4 +271,39 @@ sysRoot.destroySubcontext( rdn ); } + + + /** + * Create a person entry and try to replace a non existing indexed attribute + */ + @Test + public void testReplaceNonExistingIndexedAttribute() throws Exception + { + DirContext sysRoot = ( DirContext ) getWiredContext( ldapServer ).lookup( BASE ); + + String rdn = "cn=Kim Wilde"; + //ldapServer.getDirectoryService().getPartitions(); + + Attribute attr = new BasicAttribute( "ou", "test" ); + ModificationItem item = new ModificationItem( DirContext.REPLACE_ATTRIBUTE, attr ); + + sysRoot.modifyAttributes(rdn, new ModificationItem[] { item }); + + SearchControls sctls = new SearchControls(); + sctls.setSearchScope( SearchControls.SUBTREE_SCOPE ); + String filter = "(sn=Wilde)"; + String base = ""; + + NamingEnumeration enm = sysRoot.search( base, filter, sctls ); + + while ( enm.hasMore() ) + { + SearchResult sr = enm.next(); + Attribute ou = sr.getAttributes().get( "ou" ); + assertNotNull( ou ); + assertTrue( ou.contains( "test" ) ); + } + + sysRoot.destroySubcontext( rdn ); + } }