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/21 02:44:45 UTC
svn commit: r433107 - in /directory/branches/apacheds/1.0:
core/src/main/java/org/apache/directory/server/core/schema/
server-unit/src/test/java/org/apache/directory/server/
Author: akarasulu
Date: Sun Aug 20 17:44:44 2006
New Revision: 433107
URL: http://svn.apache.org/viewvc?rev=433107&view=rev
Log:
Fix for DIRSERVER-646: import junit.framework.TestCase;
Added:
directory/branches/apacheds/1.0/server-unit/src/test/java/org/apache/directory/server/ModifyReplaceITest.java
Modified:
directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/schema/SchemaService.java
directory/branches/apacheds/1.0/server-unit/src/test/java/org/apache/directory/server/AddingEntriesWithSpecialCharactersInRDNTest.java
Modified: directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/schema/SchemaService.java
URL: http://svn.apache.org/viewvc/directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/schema/SchemaService.java?rev=433107&r1=433106&r2=433107&view=diff
==============================================================================
--- directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/schema/SchemaService.java (original)
+++ directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/schema/SchemaService.java Sun Aug 20 17:44:44 2006
@@ -819,6 +819,19 @@
ObjectClassRegistry ocRegistry = this.globalRegistries.getObjectClassRegistry();
AttributeTypeRegistry atRegistry = this.globalRegistries.getAttributeTypeRegistry();
+ // -------------------------------------------------------------------
+ // DIRSERVER-646 Fix: Replacing an unknown attribute with no values
+ // (deletion) causes an error
+ // -------------------------------------------------------------------
+
+ if ( mods.length == 1 &&
+ mods[0].getAttribute().size() == 0 &&
+ mods[0].getModificationOp() == DirContext.REPLACE_ATTRIBUTE &&
+ ! atRegistry.hasAttributeType( mods[0].getAttribute().getID() ) )
+ {
+ return;
+ }
+
// Now, apply the modifications on the cloned entry before applyong it to the
// real object.
for ( int ii = 0; ii < mods.length; ii++ )
Modified: directory/branches/apacheds/1.0/server-unit/src/test/java/org/apache/directory/server/AddingEntriesWithSpecialCharactersInRDNTest.java
URL: http://svn.apache.org/viewvc/directory/branches/apacheds/1.0/server-unit/src/test/java/org/apache/directory/server/AddingEntriesWithSpecialCharactersInRDNTest.java?rev=433107&r1=433106&r2=433107&view=diff
==============================================================================
--- directory/branches/apacheds/1.0/server-unit/src/test/java/org/apache/directory/server/AddingEntriesWithSpecialCharactersInRDNTest.java (original)
+++ directory/branches/apacheds/1.0/server-unit/src/test/java/org/apache/directory/server/AddingEntriesWithSpecialCharactersInRDNTest.java Sun Aug 20 17:44:44 2006
@@ -13,11 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*
- */package org.apache.directory.server;
+ */
+package org.apache.directory.server;
+
import java.util.Hashtable;
-import javax.naming.Context;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.directory.Attribute;
@@ -31,7 +32,6 @@
import org.apache.directory.server.unit.AbstractServerTest;
-import junit.framework.TestCase;
/**
* Test case to demonstrate DIRSERVER-631 ("Creation of entry with special (and
Added: directory/branches/apacheds/1.0/server-unit/src/test/java/org/apache/directory/server/ModifyReplaceITest.java
URL: http://svn.apache.org/viewvc/directory/branches/apacheds/1.0/server-unit/src/test/java/org/apache/directory/server/ModifyReplaceITest.java?rev=433107&view=auto
==============================================================================
--- directory/branches/apacheds/1.0/server-unit/src/test/java/org/apache/directory/server/ModifyReplaceITest.java (added)
+++ directory/branches/apacheds/1.0/server-unit/src/test/java/org/apache/directory/server/ModifyReplaceITest.java Sun Aug 20 17:44:44 2006
@@ -0,0 +1,135 @@
+package org.apache.directory.server;
+
+
+import java.util.Hashtable;
+
+import javax.naming.Context;
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+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.InitialDirContext;
+import javax.naming.directory.ModificationItem;
+import javax.naming.directory.SearchControls;
+import javax.naming.directory.SearchResult;
+
+import org.apache.directory.server.unit.AbstractServerTest;
+
+
+/**
+ * Test case for all modify replace operations.
+ *
+ * Testcase to demonstrate DIRSERVER-646 ("Replacing an unknown attribute with
+ * no values (deletion) causes an error").
+ */
+public class ModifyReplaceITest extends AbstractServerTest
+{
+ DirContext ctx = null;
+
+
+ protected Attributes getPersonAttributes( String sn, String cn )
+ {
+ 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 );
+
+ return attrs;
+ }
+
+
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+
+ Hashtable env = new Hashtable();
+ env.put( Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory" );
+ env.put( Context.PROVIDER_URL, "ldap://localhost:" + super.port + "/ou=system" );
+ env.put( Context.SECURITY_PRINCIPAL, "uid=admin,ou=system" );
+ env.put( Context.SECURITY_CREDENTIALS, "secret" );
+ env.put( Context.SECURITY_AUTHENTICATION, "simple" );
+
+ ctx = new InitialDirContext( env );
+ }
+
+
+ protected void tearDown() throws Exception
+ {
+ ctx.close();
+ super.tearDown();
+ }
+
+
+ /**
+ * Create a person entry and try to remove a not present attribute
+ */
+ public void testReplaceNotPresentAttribute() throws NamingException
+ {
+ Attributes attrs = getPersonAttributes( "Bush", "Kate Bush" );
+ String rdn = "cn=Kate Bush";
+ ctx.createSubcontext( rdn, attrs );
+
+ Attribute attr = new BasicAttribute( "description" );
+ ModificationItem item = new ModificationItem( DirContext.REPLACE_ATTRIBUTE, attr );
+
+ ctx.modifyAttributes( rdn, new ModificationItem[]
+ { item } );
+
+ SearchControls sctls = new SearchControls();
+ sctls.setSearchScope( SearchControls.SUBTREE_SCOPE );
+ String filter = "(sn=Bush)";
+ String base = "";
+
+ NamingEnumeration enm = ctx.search( base, filter, sctls );
+ while ( enm.hasMore() )
+ {
+ SearchResult sr = ( SearchResult ) enm.next();
+ attrs = sr.getAttributes();
+ Attribute cn = sr.getAttributes().get( "cn" );
+ assertNotNull( cn );
+ assertTrue( cn.contains( "Kate Bush" ) );
+ }
+
+ ctx.destroySubcontext( rdn );
+ }
+
+
+ /**
+ * Create a person entry and try to remove a non existing attribute
+ */
+ public void testReplaceNonExistingAttribute() throws NamingException
+ {
+ Attributes attrs = getPersonAttributes( "Bush", "Kate Bush" );
+ String rdn = "cn=Kate Bush";
+ ctx.createSubcontext( rdn, attrs );
+
+ Attribute attr = new BasicAttribute( "numberOfOctaves" );
+ ModificationItem item = new ModificationItem( DirContext.REPLACE_ATTRIBUTE, attr );
+
+ ctx.modifyAttributes( rdn, new ModificationItem[]
+ { item } );
+
+ SearchControls sctls = new SearchControls();
+ sctls.setSearchScope( SearchControls.SUBTREE_SCOPE );
+ String filter = "(sn=Bush)";
+ String base = "";
+
+ NamingEnumeration enm = ctx.search( base, filter, sctls );
+ while ( enm.hasMore() )
+ {
+ SearchResult sr = ( SearchResult ) enm.next();
+ attrs = sr.getAttributes();
+ Attribute cn = sr.getAttributes().get( "cn" );
+ assertNotNull( cn );
+ assertTrue( cn.contains( "Kate Bush" ) );
+ }
+
+ ctx.destroySubcontext( rdn );
+ }
+}