Return-Path: X-Original-To: apmail-directory-commits-archive@www.apache.org Delivered-To: apmail-directory-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 4E9207C8C for ; Fri, 11 Nov 2011 09:57:55 +0000 (UTC) Received: (qmail 75262 invoked by uid 500); 11 Nov 2011 09:57:55 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 75205 invoked by uid 500); 11 Nov 2011 09:57:54 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 75198 invoked by uid 99); 11 Nov 2011 09:57:54 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 11 Nov 2011 09:57:54 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 11 Nov 2011 09:57:52 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 951F123889BB for ; Fri, 11 Nov 2011 09:57:32 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1200792 [2/2] - in /directory/apacheds/trunk: core-api/src/main/java/org/apache/directory/server/core/api/ core-api/src/main/java/org/apache/directory/server/core/api/interceptor/ core-api/src/main/java/org/apache/directory/server/core/api... Date: Fri, 11 Nov 2011 09:57:31 -0000 To: commits@directory.apache.org From: elecharny@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20111111095732.951F123889BB@eris.apache.org> 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=1200792&r1=1200791&r2=1200792&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 Fri Nov 11 09:57:30 2011 @@ -6,16 +6,16 @@ * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations - * under the License. - * + * under the License. + * */ package org.apache.directory.server.operations.search; @@ -42,7 +42,6 @@ import org.apache.directory.server.core. import org.apache.directory.server.core.api.filtering.EntryFilteringCursor; import org.apache.directory.server.core.api.interceptor.BaseInterceptor; import org.apache.directory.server.core.api.interceptor.Interceptor; -import org.apache.directory.server.core.api.interceptor.NextInterceptor; import org.apache.directory.server.core.api.interceptor.context.SearchOperationContext; import org.apache.directory.server.core.api.interceptor.context.SearchingOperationContext; import org.apache.directory.server.core.integ.AbstractLdapTestUnit; @@ -57,14 +56,14 @@ import org.junit.runner.RunWith; /** - * A set of tests to make sure the negation operator is working + * A set of tests to make sure the negation operator is working * properly when included in search filters on indexed attributes. * * @author Apache Directory Project */ -@RunWith ( FrameworkRunner.class ) -@CreateLdapServer ( - transports = +@RunWith ( FrameworkRunner.class ) +@CreateLdapServer ( + transports = { @CreateTransport( protocol = "LDAP" ) }) @@ -117,26 +116,26 @@ import org.junit.runner.RunWith; "uid: jnewbie", "userPassword: secret", "cn: Joe Newbie", - "sn: Newbie" - } -) -public class SearchLimitsIT extends AbstractLdapTestUnit + "sn: Newbie" +} + ) +public class SearchLimitsIT extends AbstractLdapTestUnit { /** - * An {@link Interceptor} that fakes a specified amount of delay to each + * An {@link Interceptor} that fakes a specified amount of delay to each * search iteration so we can make sure search time limits are adhered to. * * @author Apache Directory Project - */ + */ class DelayInducingInterceptor extends BaseInterceptor { private Long delayMillis; - - public EntryFilteringCursor search( NextInterceptor next, SearchOperationContext searchContext ) throws LdapException + + public EntryFilteringCursor search( SearchOperationContext searchContext ) throws LdapException { - EntryFilteringCursor cursor = next.search( searchContext ); + EntryFilteringCursor cursor = next( searchContext ); cursor.addEntryFilter( new EntryFilter() { public boolean accept( SearchingOperationContext operation, Entry result ) throws Exception { @@ -148,51 +147,52 @@ public class SearchLimitsIT extends Abst return true; } }); + return cursor; } - - + + public void setDelayMillis( long delayMillis ) { if ( delayMillis <= 0 ) { this.delayMillis = null; } - + this.delayMillis = delayMillis; } } - + private int oldMaxTimeLimit; private long oldMaxSizeLimit; private DelayInducingInterceptor delayInterceptor; - + @Before public void setUp() throws Exception { oldMaxTimeLimit = getLdapServer().getMaxTimeLimit(); oldMaxSizeLimit = getLdapServer().getMaxSizeLimit(); delayInterceptor = new DelayInducingInterceptor(); - getLdapServer().getDirectoryService().getInterceptorChain().addFirst( delayInterceptor ); + getLdapServer().getDirectoryService().addFirst( delayInterceptor ); } - - + + @After public void tearDown() throws Exception { getLdapServer().setMaxTimeLimit( oldMaxTimeLimit ); getLdapServer().setMaxSizeLimit( oldMaxSizeLimit ); - getLdapServer().getDirectoryService().getInterceptorChain().remove( DelayInducingInterceptor.class.getSimpleName() ); + getLdapServer().getDirectoryService().remove( DelayInducingInterceptor.class.getSimpleName() ); } - + // ----------------------------------------------------------------------- // 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 @@ -203,14 +203,14 @@ public class SearchLimitsIT extends Abst { getLdapServer().setMaxTimeLimit( LdapServer.NO_TIME_LIMIT ); delayInterceptor.setDelayMillis( 500 ); - + getActorsWithLimit( "(objectClass=*)", 499, LdapServer.NO_SIZE_LIMIT ); } - + /** - * Sets up the server with longer search time limit than the request's - * which constrains time by request time limit value to cause a time limit + * Sets up the server with longer search time limit than the request's + * which constrains time by request time limit value to cause a time limit * exceeded exception on the client. */ @Test ( expected = TimeLimitExceededException.class ) @@ -218,14 +218,14 @@ public class SearchLimitsIT extends Abst { getLdapServer().setMaxTimeLimit( 10000 ); // this is in seconds delayInterceptor.setDelayMillis( 500 ); - + getActorsWithLimit( "(objectClass=*)", 499, LdapServer.NO_SIZE_LIMIT ); } - + /** - * Sets up the server with shorter search time limit than the request's - * which constrains time by using server max limit value to cause a time + * Sets up the server with shorter search time limit than the request's + * which constrains time by using server max limit value to cause a time * limit exceeded exception on the client. */ @Test ( expected = TimeLimitExceededException.class ) @@ -233,46 +233,46 @@ public class SearchLimitsIT extends Abst { getLdapServer().setMaxTimeLimit( 1 ); // this is in seconds delayInterceptor.setDelayMillis( 1100 ); - + getActorsWithLimit( "(objectClass=*)", 100000, LdapServer.NO_SIZE_LIMIT ); } - + /** * Sets up the server with limited search time with unlimited request * time limit. Should work just fine for the administrative user. */ - @Test + @Test public void testRequestUnlimitedConfigurationLimited() throws Exception { getLdapServer().setMaxTimeLimit( 1 ); // this is in seconds delayInterceptor.setDelayMillis( 500 ); - - getActorsWithLimit( "(objectClass=*)", + + getActorsWithLimit( "(objectClass=*)", LdapServer.NO_TIME_LIMIT, LdapServer.NO_SIZE_LIMIT ); } - + /** * Sets up the server with limited search time with unlimited request * time limit. Should not work for non administrative users. */ - @Test ( expected = TimeLimitExceededException.class ) + @Test ( expected = TimeLimitExceededException.class ) public void testNonAdminRequestUnlimitedConfigurationLimited() throws Exception { getLdapServer().setMaxTimeLimit( 1 ); // this is in seconds delayInterceptor.setDelayMillis( 500 ); - - getActorsWithLimitNonAdmin( "(objectClass=*)", + + getActorsWithLimitNonAdmin( "(objectClass=*)", LdapServer.NO_TIME_LIMIT, LdapServer.NO_SIZE_LIMIT ); } - - + + // ----------------------------------------------------------------------- // 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 @@ -282,78 +282,78 @@ public class SearchLimitsIT extends Abst public void testRequestConstrainedUnlimitByConfigurationSize() throws Exception { getLdapServer().setMaxSizeLimit( LdapServer.NO_SIZE_LIMIT ); - + getActorsWithLimit( "(objectClass=*)", LdapServer.NO_TIME_LIMIT, 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 + * 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 { - getLdapServer().setMaxSizeLimit( 10000 ); + getLdapServer().setMaxSizeLimit( 10000 ); getActorsWithLimit( "(objectClass=*)", LdapServer.NO_TIME_LIMIT, 1 ); } /** - * Sets up the server with shorter search size limit than the request's - * which constrains size by using server max limit value. Should work + * Sets up the server with shorter search size limit than the request's + * which constrains size by using server max limit value. Should work * just fine for the administrative user. */ @Test public void testRequestConstrainedGreaterThanConfigurationSize() throws Exception { - getLdapServer().setMaxSizeLimit( 1 ); + getLdapServer().setMaxSizeLimit( 1 ); Set set = getActorsWithLimit( "(objectClass=*)", LdapServer.NO_TIME_LIMIT, 100000 ); assertEquals( 4, set.size() ); } /** - * 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 + * 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 ) + @Test (expected = SizeLimitExceededException.class ) public void testNonAdminRequestConstrainedGreaterThanConfigurationSize() throws Exception { - getLdapServer().setMaxSizeLimit( 1 ); - + getLdapServer().setMaxSizeLimit( 1 ); + // We are not using the admin : it should fail getActorsWithLimitNonAdmin( "(objectClass=*)", LdapServer.NO_TIME_LIMIT, 100000 ); } - + /** * Sets up the server with limited search size with unlimited request * size limit. Should work just fine for the administrative user. */ - @Test + @Test public void testRequestUnlimitedConfigurationLimitedSize() throws Exception { - getLdapServer().setMaxSizeLimit( 1 ); - Set set = getActorsWithLimit( "(objectClass=*)", + getLdapServer().setMaxSizeLimit( 1 ); + Set set = getActorsWithLimit( "(objectClass=*)", LdapServer.NO_TIME_LIMIT, LdapServer.NO_SIZE_LIMIT ); - + 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 ) + @Test ( expected = SizeLimitExceededException.class ) public void testNonAdminRequestUnlimitedConfigurationLimitedSize() throws Exception { getLdapServer().setMaxSizeLimit( 1 ); - getActorsWithLimitNonAdmin( "(objectClass=*)", + getActorsWithLimitNonAdmin( "(objectClass=*)", LdapServer.NO_TIME_LIMIT, LdapServer.NO_SIZE_LIMIT ); } @@ -373,7 +373,7 @@ public class SearchLimitsIT extends Abst public void testRequestConstraintedLessThanExpectedSize() throws Exception { getLdapServer().setMaxSizeLimit( LdapServer.NO_SIZE_LIMIT ); - + getActorsWithLimit( "(objectClass=*)", LdapServer.NO_TIME_LIMIT, 3 ); } @@ -425,7 +425,7 @@ public class SearchLimitsIT extends Abst controls.setCountLimit( 1 ); controls.setSearchScope( SearchControls.OBJECT_SCOPE ); - NamingEnumeration namingEnumeration = + NamingEnumeration namingEnumeration = ctx.search( "ou=actors,ou=system", filter, controls ); assertTrue( namingEnumeration.hasMore() ); namingEnumeration.next(); @@ -436,8 +436,8 @@ public class SearchLimitsIT extends Abst // ----------------------------------------------------------------------- // Utility Methods // ----------------------------------------------------------------------- - - + + /** * Do a search request from the ou=actors,ou=system base, with a principal * which is the administrator. @@ -450,15 +450,15 @@ public class SearchLimitsIT extends Abst controls.setTimeLimit( timeLimitMillis ); controls.setCountLimit( sizeLimit ); controls.setSearchScope( SearchControls.ONELEVEL_SCOPE ); - - NamingEnumeration namingEnumeration = + + NamingEnumeration namingEnumeration = ctx.search( "ou=actors,ou=system", filter, controls ); - + while( namingEnumeration.hasMore() ) { results.add( namingEnumeration.next().getNameInNamespace() ); } - + return results; } @@ -466,24 +466,24 @@ public class SearchLimitsIT extends Abst * Do a search request from the ou=actors,ou=system base, with a principal * which is not the administrator. */ - private Set getActorsWithLimitNonAdmin( String filter, int timeLimitMillis, long sizeLimit ) + private Set getActorsWithLimitNonAdmin( String filter, int timeLimitMillis, long sizeLimit ) throws Exception - { + { DirContext ctx = getWiredContext( getLdapServer(), "uid=jblack,ou=actors,ou=system", "secret" ); Set results = new HashSet(); SearchControls controls = new SearchControls(); controls.setTimeLimit( timeLimitMillis ); controls.setCountLimit( sizeLimit ); controls.setSearchScope( SearchControls.ONELEVEL_SCOPE ); - - NamingEnumeration namingEnumeration = + + NamingEnumeration namingEnumeration = ctx.search( "ou=actors,ou=system", filter, controls ); - + while( namingEnumeration.hasMore() ) { results.add( namingEnumeration.next().getNameInNamespace() ); } - + return results; - } + } }