directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From seelm...@apache.org
Subject svn commit: r712718 - in /directory: apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/operations/search/ apacheds/trunk/core/src/main/java/org/apache/directory/server/core/normalization/ apacheds/trunk/server-integ/src/test/java...
Date Mon, 10 Nov 2008 18:37:39 GMT
Author: seelmann
Date: Mon Nov 10 10:37:37 2008
New Revision: 712718

URL: http://svn.apache.org/viewvc?rev=712718&view=rev
Log:
DIRSERVER-1287:
o Usage of Pattern.quote() when composing regular expression for substring search
o Interim fix in NormalizingVisitor.decodeEscapedHex() to make a filters like (cn=\5C) working
o Fixed test in AndCursurTest
o Added some tests


Modified:
    directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/operations/search/SearchIT.java
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/normalization/NormalizingVisitor.java
    directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/search/SearchIT.java
    directory/apacheds/trunk/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/AndCursorTest.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java
    directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/util/StringToolsTest.java

Modified: directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/operations/search/SearchIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/operations/search/SearchIT.java?rev=712718&r1=712717&r2=712718&view=diff
==============================================================================
--- directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/operations/search/SearchIT.java
(original)
+++ directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/operations/search/SearchIT.java
Mon Nov 10 10:37:37 2008
@@ -1256,7 +1256,7 @@
         assertFalse( results.contains( "cn=testGroup4,ou=groups,ou=system" ) );
         assertTrue( results.contains( "cn=testGroup5,ou=groups,ou=system" ) );
     }
-    
+
 
     @Test
     public void testSearchWithEscapedCharsInFilter() throws Exception
@@ -1271,28 +1271,30 @@
         vicious.put( ocls );
         vicious.put( "cn", "Sid Vicious" );
         vicious.put( "sn", "Vicious" );
-        vicious.put(  "description", "(sex pistols)" );
+        vicious.put( "description", "(sex*pis\\tols)" );
         DirContext ctx = sysRoot.createSubcontext( "cn=Sid Vicious", vicious );
         assertNotNull( ctx );
 
         ctx = ( DirContext ) sysRoot.lookup( "cn=Sid Vicious" );
         assertNotNull( ctx );
-        
+
         Attributes attributes = ctx.getAttributes( "" );
-        
-        assertEquals( "(sex pistols)", attributes.get( "description" ).get() );
+
+        assertEquals( "(sex*pis\\tols)", attributes.get( "description" ).get() );
 
         // Now, search for the description
         SearchControls controls = new SearchControls();
         controls.setSearchScope( SearchControls.SUBTREE_SCOPE );
         controls.setDerefLinkFlag( false );
-        controls.setReturningAttributes( new String[] { "*" } );
-        sysRoot.addToEnvironment( JndiPropertyConstants.JNDI_LDAP_DAP_DEREF_ALIASES,
-                AliasDerefMode.NEVER_DEREF_ALIASES.getJndiValue() );
+        controls.setReturningAttributes( new String[]
+            { "*" } );
+        sysRoot.addToEnvironment( JndiPropertyConstants.JNDI_LDAP_DAP_DEREF_ALIASES, AliasDerefMode.NEVER_DEREF_ALIASES
+            .getJndiValue() );
         HashMap<String, Attributes> map = new HashMap<String, Attributes>();
 
-        NamingEnumeration<SearchResult> list = sysRoot.search( "", "(description=\\28sex
pistols\\29)", controls );
-        
+        NamingEnumeration<SearchResult> list = sysRoot
+            .search( "", "(description=\\28sex\\2Apis\\5Ctols\\29)", controls );
+
         while ( list.hasMore() )
         {
             SearchResult result = list.next();
@@ -1308,6 +1310,62 @@
     }
 
 
+    @Test
+    public void testSubstringSearchWithEscapedCharsInFilter() throws Exception
+    {
+        // Create an entry with special chars in the description attribute
+        LdapContext sysRoot = getSystemContext( service );
+        // Create entry cn=Sid Vicious, ou=system
+        Attributes vicious = new BasicAttributes( true );
+        Attribute ocls = new BasicAttribute( "objectClass" );
+        ocls.add( "top" );
+        ocls.add( "person" );
+        vicious.put( ocls );
+        vicious.put( "cn", "Sid Vicious" );
+        vicious.put( "sn", "Vicious" );
+        vicious.put( "description", "(sex*pis\\tols)" );
+        DirContext ctx = sysRoot.createSubcontext( "cn=Sid Vicious", vicious );
+        assertNotNull( ctx );
+
+        ctx = ( DirContext ) sysRoot.lookup( "cn=Sid Vicious" );
+        assertNotNull( ctx );
+
+        Attributes attributes = ctx.getAttributes( "" );
+
+        assertEquals( "(sex*pis\\tols)", attributes.get( "description" ).get() );
+
+        // Now, search for the description
+        SearchControls controls = new SearchControls();
+        controls.setSearchScope( SearchControls.SUBTREE_SCOPE );
+        controls.setDerefLinkFlag( false );
+        controls.setReturningAttributes( new String[]
+            { "*" } );
+        sysRoot.addToEnvironment( JndiPropertyConstants.JNDI_LDAP_DAP_DEREF_ALIASES, AliasDerefMode.NEVER_DEREF_ALIASES
+            .getJndiValue() );
+
+        String[] filters = new String[]
+            { "(description=*\\28*)", "(description=*\\29*)", "(description=*\\2A*)", "(description=*\\5C*)"
};
+        for ( String filter : filters )
+        {
+            HashMap<String, Attributes> map = new HashMap<String, Attributes>();
+            NamingEnumeration<SearchResult> list = sysRoot.search( "", filter, controls
);
+
+            while ( list.hasMore() )
+            {
+                SearchResult result = list.next();
+                map.put( result.getName(), result.getAttributes() );
+            }
+
+            assertEquals( "Expected number of results returned was incorrect!", 1, map.size()
);
+
+            Attributes attrs = map.get( "cn=Sid Vicious,ou=system" );
+
+            assertNotNull( attrs.get( "objectClass" ) );
+            assertNotNull( attrs.get( "cn" ) );
+        }
+    }
+
+
     /**
      * Test a search with a bad filter : there is a missing closing ')'
      */

Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/normalization/NormalizingVisitor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/normalization/NormalizingVisitor.java?rev=712718&r1=712717&r2=712718&view=diff
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/normalization/NormalizingVisitor.java
(original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/normalization/NormalizingVisitor.java
Mon Nov 10 10:37:37 2008
@@ -179,7 +179,13 @@
         if ( escaped )
         {
             // We should not have a '\' at the end of the string
-            throw new InvalidNameException( "The value must not ends with a '\\'." );
+            //throw new InvalidNameException( "The value must not ends with a '\\'." );
+            
+            // TODO: We have a weird behaviour:
+            // - If a request (cn=\5C) comes over the wire the '\5C' is already decoded to
a '\'.
+            // - If we use the embedded LdapContext it is not decoded here.
+            // This is just a hack to make it working.
+            buf.append( '\\' );
         }
 
         return buf.toString();

Modified: directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/search/SearchIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/search/SearchIT.java?rev=712718&r1=712717&r2=712718&view=diff
==============================================================================
--- directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/search/SearchIT.java
(original)
+++ directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/search/SearchIT.java
Mon Nov 10 10:37:37 2008
@@ -20,7 +20,16 @@
 package org.apache.directory.server.operations.search;
 
 
+import static org.apache.directory.server.integ.ServerIntegrationUtils.getWiredContext;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
 import java.util.Arrays;
+import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Set;
 
@@ -44,19 +53,10 @@
 import org.apache.directory.server.core.subtree.SubentryInterceptor;
 import org.apache.directory.server.integ.SiRunner;
 import org.apache.directory.server.ldap.LdapService;
-
-import static org.apache.directory.server.integ.ServerIntegrationUtils.getWiredContext;
-
 import org.apache.directory.shared.ldap.constants.SchemaConstants;
 import org.apache.directory.shared.ldap.message.control.SubentriesControl;
 import org.junit.Test;
 import org.junit.runner.RunWith;
-import static org.junit.Assert.fail;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
 
 
 /**
@@ -1377,8 +1377,46 @@
 
         result.close();
     }
-   
-    
+
+
+    @Test
+    public void testSubstringSearchWithEscapedCharsInFilter() throws Exception
+    {
+        LdapContext ctx = ( LdapContext ) getWiredContext( ldapService ).lookup( BASE );
+
+        Attributes attrs = new BasicAttributes( "objectClass", "inetOrgPerson", true );
+        attrs.get( "objectClass" ).add( "organizationalPerson" );
+        attrs.get( "objectClass" ).add( "person" );
+        attrs.put( "givenName", "Jim" );
+        attrs.put( "sn", "Bean" );
+        attrs.put( "cn", "jimbean" );
+        attrs.put( "description", "(sex*pis\\tols)" );
+        ctx.createSubcontext( "cn=jimbean", attrs );
+
+        SearchControls controls = new SearchControls();
+        controls.setSearchScope( SearchControls.ONELEVEL_SCOPE );
+        controls.setReturningAttributes( new String[]
+            { "cn" } );
+
+        String[] filters = new String[]
+            { "(description=*\\28*)", "(description=*\\29*)", "(description=*\\2A*)", "(description=*\\5C*)"
};
+        for ( String filter : filters )
+        {
+            HashMap<String, Attributes> map = new HashMap<String, Attributes>();
+            NamingEnumeration<SearchResult> res = ctx.search( "", filter, controls
);
+            assertTrue( res.hasMore() );
+            SearchResult result = res.next();
+            assertNotNull( result );
+            attrs = result.getAttributes();
+            assertEquals( 1, attrs.size() );
+            assertNotNull( attrs.get( "cn" ) );
+            assertEquals( 1, attrs.get( "cn" ).size() );
+            assertEquals( "jimbean", ( String ) attrs.get( "cn" ).get() );
+            assertFalse( res.hasMore() );
+        }
+    }
+
+
     /**
      * Test for DIRSERVER-1180 where search hangs when an invalid a substring 
      * expression missing an any field is used in a filter: i.e. (cn=**).
@@ -1408,4 +1446,5 @@
             assertTrue( true );
         }
     }
+
 }

Modified: directory/apacheds/trunk/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/AndCursorTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/AndCursorTest.java?rev=712718&r1=712717&r2=712718&view=diff
==============================================================================
--- directory/apacheds/trunk/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/AndCursorTest.java
(original)
+++ directory/apacheds/trunk/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/AndCursorTest.java
Mon Nov 10 10:37:37 2008
@@ -189,7 +189,7 @@
         List<Evaluator<? extends ExprNode,ServerEntry>> evaluators = new ArrayList<Evaluator<?
extends ExprNode,ServerEntry>>();
         Evaluator<? extends ExprNode, ServerEntry> eval;
         
-        ExprNode exprNode = new SubstringNode( "cn", "J*", null );
+        ExprNode exprNode = new SubstringNode( "cn", "J", null );
         eval = new SubstringEvaluator( ( SubstringNode ) exprNode, store, registries );
         IndexCursor<?,ServerEntry> wrapped = new SubstringCursor( store, ( SubstringEvaluator
) eval );
         

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java?rev=712718&r1=712717&r2=712718&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java
Mon Nov 10 10:37:37 2008
@@ -803,20 +803,20 @@
 
         if ( initialPattern != null )
         {
-            buf.append( '^' ).append( initialPattern );
+            buf.append( '^' ).append( Pattern.quote( initialPattern ) );
         }
 
         if ( anyPattern != null )
         {
             for ( int i = 0; i < anyPattern.length; i++ )
             {
-                buf.append( ".*" ).append( anyPattern[i] );
+                buf.append( ".*" ).append( Pattern.quote( anyPattern[i] ) );
             }
         }
 
         if ( finalPattern != null )
         {
-            buf.append( ".*" ).append( finalPattern );
+            buf.append( ".*" ).append( Pattern.quote( finalPattern ) );
         }
         else
         {

Modified: directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/util/StringToolsTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/util/StringToolsTest.java?rev=712718&r1=712717&r2=712718&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/util/StringToolsTest.java
(original)
+++ directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/util/StringToolsTest.java
Mon Nov 10 10:37:37 2008
@@ -289,6 +289,29 @@
     }
 
 
+    /**
+     * Tests StringTools.getRegex() with some LDAP filter special characters.
+     */
+    public void testGetRegexpWithLdapFilterSpecialChars() throws Exception
+    {
+        Pattern[] patterns = new Pattern[]
+            { StringTools.getRegex( null, new String[]
+                { "(" }, null ), StringTools.getRegex( null, new String[]
+                { ")" }, null ), StringTools.getRegex( null, new String[]
+                { "*" }, null ), StringTools.getRegex( null, new String[]
+                { "\\" }, null ), };
+
+        for ( Pattern pattern : patterns )
+        {
+            boolean b1 = pattern.matcher( "a(b*c\\d)e" ).matches();
+            assertTrue( b1 );
+
+            boolean b3 = pattern.matcher( "Test test" ).matches();
+            assertFalse( b3 );
+        }
+    }
+
+
     public void testDeepTrim()
     {
         assertEquals( "", StringTools.deepTrim( " ", false ) );



Mime
View raw message