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 2012/02/22 16:33:59 UTC

svn commit: r1292346 - in /directory/apacheds/trunk: interceptors/normalization/src/main/java/org/apache/directory/server/core/normalization/ ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/

Author: elecharny
Date: Wed Feb 22 15:33:59 2012
New Revision: 1292346

URL: http://svn.apache.org/viewvc?rev=1292346&view=rev
Log:
Applied a fix for DIRAPI-81 : we now can create entry with a RDN containing escaped values that are stored in the server as is.

Modified:
    directory/apacheds/trunk/interceptors/normalization/src/main/java/org/apache/directory/server/core/normalization/NormalizationInterceptor.java
    directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/ClientAddRequestTest.java

Modified: directory/apacheds/trunk/interceptors/normalization/src/main/java/org/apache/directory/server/core/normalization/NormalizationInterceptor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/interceptors/normalization/src/main/java/org/apache/directory/server/core/normalization/NormalizationInterceptor.java?rev=1292346&r1=1292345&r2=1292346&view=diff
==============================================================================
--- directory/apacheds/trunk/interceptors/normalization/src/main/java/org/apache/directory/server/core/normalization/NormalizationInterceptor.java (original)
+++ directory/apacheds/trunk/interceptors/normalization/src/main/java/org/apache/directory/server/core/normalization/NormalizationInterceptor.java Wed Feb 22 15:33:59 2012
@@ -433,7 +433,7 @@ public class NormalizationInterceptor ex
                 // 1) The attribute does not exist
                 if ( !entry.containsAttribute( upId ) )
                 {
-                    entry.add( upId, value );
+                    entry.add( upId, upValue );
                 }
                 // 2) The attribute exists
                 else
@@ -444,12 +444,12 @@ public class NormalizationInterceptor ex
                     if ( at.isSingleValued() )
                     {
                         entry.removeAttributes( upId );
-                        entry.add( upId, value );
+                        entry.add( upId, upValue );
                     }
                     // 2.2 the attribute is multi-valued : add the missing value
                     else
                     {
-                        entry.add( upId, value );
+                        entry.add( upId, upValue );
                     }
                 }
             }

Modified: directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/ClientAddRequestTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/ClientAddRequestTest.java?rev=1292346&r1=1292345&r2=1292346&view=diff
==============================================================================
--- directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/ClientAddRequestTest.java (original)
+++ directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/ClientAddRequestTest.java Wed Feb 22 15:33:59 2012
@@ -26,6 +26,8 @@ import static org.junit.Assert.assertNot
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
+import java.util.HashSet;
+import java.util.Set;
 import java.util.UUID;
 import java.util.concurrent.TimeUnit;
 
@@ -40,8 +42,10 @@ import org.apache.directory.server.core.
 import org.apache.directory.shared.client.api.LdapApiIntegrationUtils;
 import org.apache.directory.shared.ldap.model.constants.SchemaConstants;
 import org.apache.directory.shared.ldap.model.csn.CsnFactory;
+import org.apache.directory.shared.ldap.model.entry.Attribute;
 import org.apache.directory.shared.ldap.model.entry.DefaultEntry;
 import org.apache.directory.shared.ldap.model.entry.Entry;
+import org.apache.directory.shared.ldap.model.entry.Value;
 import org.apache.directory.shared.ldap.model.exception.LdapNoPermissionException;
 import org.apache.directory.shared.ldap.model.message.AddRequest;
 import org.apache.directory.shared.ldap.model.message.AddRequestImpl;
@@ -254,4 +258,93 @@ public class ClientAddRequestTest extend
         }
     }
 
+    
+    @Test
+    /**
+     * tests adding en entry with escaped chars in the RDN
+     */
+    public void testAddEntryWithRdnContainingEscapedChars() throws Exception
+    {
+        //test as admin first
+        Dn dn = new Dn( "cn=a\\+B,ou=system" );
+        Entry entry = new DefaultEntry( dn,
+            "ObjectClass: top",
+            "ObjectClass: person",
+            "sn: x" );
+
+        connection.add( entry );
+
+        Entry loadedEntry = connection.lookup( dn.getName(), "*" );
+        assertNotNull( loadedEntry );
+        assertTrue( loadedEntry.containsAttribute( "cn" ) );
+        
+        String cn = loadedEntry.get( "cn" ).get().getString();
+        
+        assertEquals( "a+B", cn );
+    }
+
+    
+    @Test
+    /**
+     * tests adding en entry with escaped chars in the RDN
+     */
+    public void testAddEntryWithRdnContainingEscapedCharsExistingnEntry() throws Exception
+    {
+        //test as admin first
+        Dn dn = new Dn( "cn=a\\+B,ou=system" );
+        Entry entry = new DefaultEntry( dn,
+            "ObjectClass: top",
+            "ObjectClass: person",
+            "cn: a+b",
+            "sn: x" );
+
+        connection.add( entry );
+
+        Entry loadedEntry = connection.lookup( dn.getName(), "*" );
+        assertNotNull( loadedEntry );
+        assertTrue( loadedEntry.containsAttribute( "cn" ) );
+        
+        String cn = loadedEntry.get( "cn" ).get().getString();
+        
+        assertEquals( "a+b", cn );
+    }
+
+    
+    @Test
+    /**
+     * tests adding en entry with escaped chars in the RDN
+     */
+    public void testAddEntryWithRdnContainingEscapedCharsMultiValued() throws Exception
+    {
+        //test as admin first
+        Dn dn = new Dn( "cn=a\\+B,ou=system" );
+        Entry entry = new DefaultEntry( dn,
+            "ObjectClass: top",
+            "ObjectClass: person",
+            "cn: c",
+            "sn: x" );
+
+        connection.add( entry );
+
+        Entry loadedEntry = connection.lookup( dn.getName(), "*" );
+        assertNotNull( loadedEntry );
+        assertTrue( loadedEntry.containsAttribute( "cn" ) );
+        
+        Attribute attribute = loadedEntry.get( "cn" );
+        Set<String> expected = new HashSet<String>();
+        expected.add( "a+B" );
+        expected.add( "c" );
+        int count = 0;
+        
+        for ( Value<?> value : attribute )
+        {
+            String val = value.getString();
+            
+            assertTrue( expected.contains( val ) );
+            count++;
+            
+        }
+        
+        assertEquals( 2, count );
+    }
 }