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 2008/08/18 23:29:07 UTC
svn commit: r686871 -
/directory/apacheds/branches/bigbang/server-integ/src/test/java/org/apache/directory/server/operations/modify/ModifyReplaceIT.java
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<Index<?,ServerEntry>> indexedAttrs = new HashSet<Index<?,ServerEntry>>();
+ indexedAttrs.add( new JdbmIndex<String,ServerEntry>( SchemaConstants.OBJECT_CLASS_AT ) );
+ indexedAttrs.add( new JdbmIndex<String,ServerEntry>( 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<String, MechanismHandler> mechanismHandlerMap = new HashMap<String,MechanismHandler>();
+ 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<SearchResult> 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 );
+ }
}