directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r687569 - in /directory/apacheds/trunk: protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/SearchHandler.java server-integ/src/test/java/org/apache/directory/server/operations/search/SearchLimitsIT.java
Date Thu, 21 Aug 2008 05:59:56 GMT
Author: akarasulu
Date: Wed Aug 20 22:59:56 2008
New Revision: 687569

URL: http://svn.apache.org/viewvc?rev=687569&view=rev
Log:
clean imports and adding size limit test cases

Modified:
    directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/SearchHandler.java
    directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/search/SearchLimitsIT.java

Modified: directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/SearchHandler.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/SearchHandler.java?rev=687569&r1=687568&r2=687569&view=diff
==============================================================================
--- directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/SearchHandler.java
(original)
+++ directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/SearchHandler.java
Wed Aug 20 22:59:56 2008
@@ -28,7 +28,6 @@
 import org.apache.directory.server.core.event.EventType;
 import org.apache.directory.server.core.event.NotificationCriteria;
 import org.apache.directory.server.core.filtering.EntryFilteringCursor;
-import org.apache.directory.server.ldap.LdapServer;
 import org.apache.directory.server.ldap.LdapSession;
 import org.apache.directory.shared.ldap.codec.util.LdapURL;
 import org.apache.directory.shared.ldap.codec.util.LdapURLEncodingException;
@@ -299,12 +298,17 @@
             return ldapServer.getMaxSizeLimit();
         }
         
+        if ( ldapServer.getMaxSizeLimit() == NO_SIZE_LIMIT )
+        {
+            return req.getSizeLimit();
+        }
+        
         /*
          * If the non-administrative user specifies a size limit equal to or 
          * less than the maximum limit configured in the server then we 
          * constrain search by the amount specified in the request
          */
-        if ( ldapServer.getMaxSizeLimit() >= req.getTimeLimit() )
+        if ( ldapServer.getMaxSizeLimit() >= req.getSizeLimit() )
         {
             return req.getSizeLimit();
         }
@@ -364,6 +368,7 @@
                 {
                     ClonedServerEntry entry = cursor.get();
                     session.getIoSession().write( generateResponse( session, req, entry )
);
+                    count++;
                 }
                 
                 if ( count >= sizeLimit )

Modified: directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/search/SearchLimitsIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/search/SearchLimitsIT.java?rev=687569&r1=687568&r2=687569&view=diff
==============================================================================
--- directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/search/SearchLimitsIT.java
(original)
+++ directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/search/SearchLimitsIT.java
Wed Aug 20 22:59:56 2008
@@ -33,6 +33,7 @@
 import org.apache.directory.server.core.interceptor.context.SearchingOperationContext;
 import org.apache.directory.server.integ.SiRunner;
 import static org.apache.directory.server.integ.ServerIntegrationUtils.getWiredContext;
+import static org.junit.Assert.*;
 
 import org.apache.directory.server.ldap.LdapServer;
 import org.junit.After;
@@ -41,6 +42,7 @@
 import org.junit.runner.RunWith;
 
 import javax.naming.NamingEnumeration;
+import javax.naming.SizeLimitExceededException;
 import javax.naming.TimeLimitExceededException;
 import javax.naming.directory.DirContext;
 import javax.naming.directory.SearchControls;
@@ -159,6 +161,7 @@
 
     
     private int oldMaxTimeLimit;
+    private int oldMaxSizeLimit;
     private DelayInducingInterceptor delayInterceptor;
 
     
@@ -166,6 +169,7 @@
     public void setUp() throws Exception
     {
         oldMaxTimeLimit = ldapServer.getMaxTimeLimit();
+        oldMaxSizeLimit = ldapServer.getMaxSizeLimit();
         delayInterceptor = new DelayInducingInterceptor();
         ldapServer.getDirectoryService().getInterceptorChain().addFirst( delayInterceptor
);
     }
@@ -175,10 +179,16 @@
     public void tearDown() throws Exception
     {
         ldapServer.setMaxTimeLimit( oldMaxTimeLimit );
+        ldapServer.setMaxSizeLimit( oldMaxSizeLimit );
         ldapServer.getDirectoryService().getInterceptorChain().remove( DelayInducingInterceptor.class.getName()
);
     }
     
 
+    // -----------------------------------------------------------------------
+    // Time Limit Tests
+    // -----------------------------------------------------------------------
+    
+    
     /**
      * Sets up the server with unlimited search time limit but constrains time
      * by request time limit value to cause a time limit exceeded exception on
@@ -190,7 +200,7 @@
         ldapServer.setMaxTimeLimit( LdapServer.NO_TIME_LIMIT );
         delayInterceptor.setDelayMillis( 500 );
         
-        getActorsWithTimeLimit( "(objectClass=*)", 499 );
+        getActorsWithLimit( "(objectClass=*)", 499, 0 );
     }
     
 
@@ -205,7 +215,7 @@
         ldapServer.setMaxTimeLimit( 10000 ); // this is in seconds
         delayInterceptor.setDelayMillis( 500 );
         
-        getActorsWithTimeLimit( "(objectClass=*)", 499 );
+        getActorsWithLimit( "(objectClass=*)", 499, 0 );
     }
 
     
@@ -220,7 +230,7 @@
         ldapServer.setMaxTimeLimit( 1 ); // this is in seconds
         delayInterceptor.setDelayMillis( 1100 );
         
-        getActorsWithTimeLimit( "(objectClass=*)", 100000 );
+        getActorsWithLimit( "(objectClass=*)", 100000, 0 );
     }
 
     
@@ -234,7 +244,7 @@
         ldapServer.setMaxTimeLimit( 1 ); // this is in seconds
         delayInterceptor.setDelayMillis( 500 );
         
-        getActorsWithTimeLimit( "(objectClass=*)", 0 );
+        getActorsWithLimit( "(objectClass=*)", 0, 0 );
     }
 
     
@@ -248,16 +258,91 @@
         ldapServer.setMaxTimeLimit( 1 ); // this is in seconds
         delayInterceptor.setDelayMillis( 500 );
         
-        getActorsWithTimeLimitNonAdmin( "(objectClass=*)", 0 );
+        getActorsWithLimitNonAdmin( "(objectClass=*)", 0, 0 );
+    }
+    
+    
+    // -----------------------------------------------------------------------
+    // Size Limit Tests
+    // -----------------------------------------------------------------------
+    
+    
+    /**
+     * Sets up the server with unlimited search size limit but constrains size
+     * by request size limit value to cause a size limit exceeded exception on
+     * the client.
+     */
+    @Test ( expected = SizeLimitExceededException.class )
+    public void testRequestConstrainedUnlimitByConfigurationSize() throws Exception
+    {
+        ldapServer.setMaxSizeLimit( LdapServer.NO_SIZE_LIMIT );
+        getActorsWithLimit( "(objectClass=*)", 0,  1 );
+    }
+    
+
+    /**
+     * Sets up the server with longer search size limit than the request's 
+     * which constrains size by request size limit value to cause a size limit 
+     * exceeded exception on the client.
+     */
+    @Test ( expected = SizeLimitExceededException.class )
+    public void testRequestConstrainedLessThanConfigurationSize() throws Exception
+    {
+        ldapServer.setMaxSizeLimit( 10000 ); 
+        getActorsWithLimit( "(objectClass=*)", 0, 1 );
+    }
+
+    
+    /**
+     * Sets up the server with shorter search size limit than the request's 
+     * which constrains size by using server max limit value to cause a size 
+     * limit exceeded exception on the client.
+     */
+    @Test ( expected = SizeLimitExceededException.class )
+    public void testRequestConstrainedGreaterThanConfigurationSize() throws Exception
+    {
+        ldapServer.setMaxSizeLimit( 1 ); 
+        getActorsWithLimit( "(objectClass=*)", 0, 100000 );
+    }
+
+    
+    /**
+     * Sets up the server with limited search size with unlimited request
+     * size limit.  Should work just fine for the administrative user.
+     */
+    @Test 
+    public void testRequestUnlimitedConfigurationLimitedSize() throws Exception
+    {
+        ldapServer.setMaxSizeLimit( 1 ); 
+        Set<String> set = getActorsWithLimit( "(objectClass=*)", 0, 0 );
+        assertEquals( 4, set.size() );
+    }
+
+    
+    /**
+     * Sets up the server with limited search size with unlimited request
+     * size limit.  Should not work for non administrative users.
+     */
+    @Test ( expected = SizeLimitExceededException.class ) 
+    public void testNonAdminRequestUnlimitedConfigurationLimitedSize() throws Exception
+    {
+        ldapServer.setMaxSizeLimit( 1 ); // this is in seconds
+        getActorsWithLimitNonAdmin( "(objectClass=*)", 0, 0 );
     }
 
     
-    Set<String> getActorsWithTimeLimit( String filter, int timeLimitMillis ) throws
Exception
+    // -----------------------------------------------------------------------
+    // Utility Methods
+    // -----------------------------------------------------------------------
+    
+    
+    private Set<String> getActorsWithLimit( String filter, int timeLimitMillis, int
sizeLimit ) throws Exception
     {
         DirContext ctx = getWiredContext( ldapServer );
         Set<String> results = new HashSet<String>();
         SearchControls controls = new SearchControls();
         controls.setTimeLimit( timeLimitMillis );
+        controls.setCountLimit( sizeLimit );
         controls.setSearchScope( SearchControls.ONELEVEL_SCOPE );
         
         NamingEnumeration<SearchResult> namingEnumeration = ctx.search( "ou=actors,ou=system",
filter, controls );
@@ -270,12 +355,14 @@
     }
 
     
-    Set<String> getActorsWithTimeLimitNonAdmin( String filter, int timeLimitMillis
) throws Exception
+    private Set<String> getActorsWithLimitNonAdmin( String filter, int timeLimitMillis,
int sizeLimit ) 
+        throws Exception
     {
         DirContext ctx = getWiredContext( ldapServer, "uid=jblack,ou=actors,ou=system", "secret"
);
         Set<String> results = new HashSet<String>();
         SearchControls controls = new SearchControls();
         controls.setTimeLimit( timeLimitMillis );
+        controls.setCountLimit( sizeLimit );
         controls.setSearchScope( SearchControls.ONELEVEL_SCOPE );
         
         NamingEnumeration<SearchResult> namingEnumeration = ctx.search( "ou=actors,ou=system",
filter, controls );



Mime
View raw message