directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r430261 - 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/
Date Thu, 10 Aug 2006 05:48:51 GMT
Author: akarasulu
Date: Wed Aug  9 22:48:50 2006
New Revision: 430261

URL: http://svn.apache.org/viewvc?rev=430261&view=rev
Log:
Fix for DIRSERVER-702: Trying to remove an attribute which is part of the RDN does not cause
an error.  This was a bug caused by the move to using OIDs instead of the more faulty first
alias.

Modified:
    directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/schema/SchemaChecker.java
    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/ModifyRemoveTest.java

Modified: directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/schema/SchemaChecker.java
URL: http://svn.apache.org/viewvc/directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/schema/SchemaChecker.java?rev=430261&r1=430260&r2=430261&view=diff
==============================================================================
--- directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/schema/SchemaChecker.java
(original)
+++ directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/schema/SchemaChecker.java
Wed Aug  9 22:48:50 2006
@@ -328,7 +328,7 @@
      * @param attribute the attribute being modified
      * @throws NamingException if the modify operation is removing an Rdn attribute
      */
-    public static void preventRdnChangeOnModifyReplace( Name name, int mod, Attribute attribute
)
+    public static void preventRdnChangeOnModifyReplace( Name name, int mod, Attribute attribute,
OidRegistry oidRegistry )
         throws NamingException
     {
         if ( mod != DirContext.REPLACE_ATTRIBUTE )
@@ -337,7 +337,7 @@
         }
 
         Set rdnAttributes = getRdnAttributes( name );
-        String id = ( String ) attribute.getID();
+        String id = oidRegistry.getOid( ( String ) attribute.getID() );
 
         if ( !rdnAttributes.contains( id ) )
         {

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=430261&r1=430260&r2=430261&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
Wed Aug  9 22:48:50 2006
@@ -872,7 +872,8 @@
                     break;
                         
                 case DirContext.REPLACE_ATTRIBUTE :
-                    SchemaChecker.preventRdnChangeOnModifyReplace( name, modOp, change );
+                    SchemaChecker.preventRdnChangeOnModifyReplace( name, modOp, change, 
+                        globalRegistries.getOidRegistry() );
                     SchemaChecker.preventStructuralClassRemovalOnModifyReplace( ocRegistry,
name, modOp, change );
                     
                     attr = tmpEntry.get( change.getID() );

Modified: directory/branches/apacheds/1.0/server-unit/src/test/java/org/apache/directory/server/ModifyRemoveTest.java
URL: http://svn.apache.org/viewvc/directory/branches/apacheds/1.0/server-unit/src/test/java/org/apache/directory/server/ModifyRemoveTest.java?rev=430261&r1=430260&r2=430261&view=diff
==============================================================================
--- directory/branches/apacheds/1.0/server-unit/src/test/java/org/apache/directory/server/ModifyRemoveTest.java
(original)
+++ directory/branches/apacheds/1.0/server-unit/src/test/java/org/apache/directory/server/ModifyRemoveTest.java
Wed Aug  9 22:48:50 2006
@@ -375,4 +375,95 @@
 
         ctx.destroySubcontext( rdn );
     }
+
+
+    /**
+     * Create a person entry and try to remove an attribute value from the RDN
+     * by Replacement
+     */
+    public void testReplaceRdnByEmptyValueAttribute() throws NamingException
+    {
+
+        // Create an entry
+        Attributes attrs = getPersonAttributes( "Bush", "Kate Bush" );
+        String rdn = "cn=Kate Bush";
+        ctx.createSubcontext( rdn, attrs );
+
+        // replace attribute cn with empty value (=> deletion)
+        Attribute attr = new BasicAttribute( "cn" );
+        ModificationItem item = new ModificationItem( DirContext.REPLACE_ATTRIBUTE, attr
);
+
+        try
+        {
+            ctx.modifyAttributes( rdn, new ModificationItem[]
+                { item } );
+            fail( "modify should fail" );
+        }
+        catch ( SchemaViolationException e )
+        {
+            // Expected behaviour
+        }
+
+        ctx.destroySubcontext( rdn );
+    }
+
+
+    /**
+     * Create a person entry and try to remove an attribute from the RDN
+     */
+    public void testRemoveRdnAttribute() throws NamingException
+    {
+
+        // Create an entry
+        Attributes attrs = getPersonAttributes( "Bush", "Kate Bush" );
+        String rdn = "cn=Kate Bush";
+        ctx.createSubcontext( rdn, attrs );
+
+        // replace attribute cn with empty value (=> deletion)
+        Attribute attr = new BasicAttribute( "cn" );
+        ModificationItem item = new ModificationItem( DirContext.REMOVE_ATTRIBUTE, attr );
+
+        try
+        {
+            ctx.modifyAttributes( rdn, new ModificationItem[]
+                { item } );
+            fail( "modify should fail" );
+        }
+        catch ( SchemaViolationException e )
+        {
+            // Expected behaviour
+        }
+
+        ctx.destroySubcontext( rdn );
+    }
+
+
+    /**
+     * Create a person entry and try to remove an attribute from the RDN
+     */
+    public void testRemoveRdnAttributeValue() throws NamingException
+    {
+
+        // Create an entry
+        Attributes attrs = getPersonAttributes( "Bush", "Kate Bush" );
+        String rdn = "cn=Kate Bush";
+        ctx.createSubcontext( rdn, attrs );
+
+        // replace attribute cn with empty value (=> deletion)
+        Attribute attr = new BasicAttribute( "cn", "Kate Bush" );
+        ModificationItem item = new ModificationItem( DirContext.REMOVE_ATTRIBUTE, attr );
+
+        try
+        {
+            ctx.modifyAttributes( rdn, new ModificationItem[]
+                { item } );
+            fail( "modify should fail" );
+        }
+        catch ( SchemaViolationException e )
+        {
+            // Expected behaviour
+        }
+
+        ctx.destroySubcontext( rdn );
+    }
 }



Mime
View raw message