From commits-return-19279-apmail-directory-commits-archive=directory.apache.org@directory.apache.org Thu Aug 21 04:40:40 2008 Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 34769 invoked from network); 21 Aug 2008 04:40:40 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 21 Aug 2008 04:40:40 -0000 Received: (qmail 97117 invoked by uid 500); 21 Aug 2008 04:40:39 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 97080 invoked by uid 500); 21 Aug 2008 04:40:38 -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 97071 invoked by uid 99); 21 Aug 2008 04:40:38 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 20 Aug 2008 21:40:38 -0700 X-ASF-Spam-Status: No, hits=-2000.0 required=10.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; Thu, 21 Aug 2008 04:39:50 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 9632F238899B; Wed, 20 Aug 2008 21:39:49 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r687556 - in /directory/apacheds/trunk/server-integ/src: main/java/org/apache/directory/server/integ/annotations/ test/java/org/apache/directory/server/operations/search/ test/java/org/apache/directory/server/suites/ Date: Thu, 21 Aug 2008 04:39:49 -0000 To: commits@directory.apache.org From: akarasulu@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080821043949.9632F238899B@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: akarasulu Date: Wed Aug 20 21:39:48 2008 New Revision: 687556 URL: http://svn.apache.org/viewvc?rev=687556&view=rev Log: adding tests for search limits testing, removing empty package and formatting Added: directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/search/SearchLimitsIT.java Removed: directory/apacheds/trunk/server-integ/src/main/java/org/apache/directory/server/integ/annotations/ Modified: directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/search/SearchIT.java directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/suites/StockServerISuite.java 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=687556&r1=687555&r2=687556&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 Wed Aug 20 21:39:48 2008 @@ -931,6 +931,7 @@ assertFalse( res.hasMore() ); } + @Test public void testSearchAttrCN() throws Exception { Added: 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=687556&view=auto ============================================================================== --- directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/search/SearchLimitsIT.java (added) +++ directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/search/SearchLimitsIT.java Wed Aug 20 21:39:48 2008 @@ -0,0 +1,289 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * 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. + * + */ +package org.apache.directory.server.operations.search; + + +import org.apache.directory.server.core.entry.ClonedServerEntry; +import org.apache.directory.server.core.filtering.EntryFilter; +import org.apache.directory.server.core.filtering.EntryFilteringCursor; +import org.apache.directory.server.core.integ.Level; +import org.apache.directory.server.core.integ.annotations.ApplyLdifs; +import org.apache.directory.server.core.integ.annotations.CleanupLevel; +import org.apache.directory.server.core.interceptor.BaseInterceptor; +import org.apache.directory.server.core.interceptor.Interceptor; +import org.apache.directory.server.core.interceptor.NextInterceptor; +import org.apache.directory.server.core.interceptor.context.SearchOperationContext; +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 org.apache.directory.server.ldap.LdapServer; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; + +import javax.naming.NamingEnumeration; +import javax.naming.TimeLimitExceededException; +import javax.naming.directory.DirContext; +import javax.naming.directory.SearchControls; +import javax.naming.directory.SearchResult; + +import java.util.HashSet; +import java.util.Set; + + +/** + * 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 + * @version $Rev$, $Date$ + */ +@RunWith ( SiRunner.class ) +@CleanupLevel ( Level.SUITE ) +@ApplyLdifs( { + "dn: ou=actors,ou=system\n" + + "objectClass: top\n" + + "objectClass: organizationalUnit\n" + + "ou: actors\n\n" + + + "dn: uid=jblack,ou=actors,ou=system\n" + + "objectClass: top\n" + + "objectClass: person\n" + + "objectClass: organizationalPerson\n" + + "objectClass: uidObject\n" + + "uid: jblack\n" + + "ou: comedy\n" + + "ou: adventure\n" + + "cn: Jack Black\n" + + "userPassword: secret\n" + + "sn: Black\n\n" + + + "dn: uid=bpitt,ou=actors,ou=system\n" + + "objectClass: top\n" + + "objectClass: person\n" + + "objectClass: organizationalPerson\n" + + "objectClass: uidObject\n" + + "uid: bpitt\n" + + "ou: drama\n" + + "ou: adventure\n" + + "userPassword: secret\n" + + "cn: Brad Pitt\n" + + "sn: Pitt\n\n" + + + "dn: uid=gcloony,ou=actors,ou=system\n" + + "objectClass: top\n" + + "objectClass: person\n" + + "objectClass: organizationalPerson\n" + + "objectClass: uidObject\n" + + "uid: gcloony\n" + + "ou: drama\n" + + "userPassword: secret\n" + + "cn: Goerge Cloony\n" + + "sn: Cloony\n\n" + + + "dn: uid=jnewbie,ou=actors,ou=system\n" + + "objectClass: top\n" + + "objectClass: person\n" + + "objectClass: organizationalPerson\n" + + "objectClass: uidObject\n" + + "uid: jnewbie\n" + + "userPassword: secret\n" + + "cn: Joe Newbie\n" + + "sn: Newbie\n\n" + } +) +public class SearchLimitsIT +{ + public static LdapServer ldapServer; + + + /** + * 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 + * @version $Rev$, $Date$ + */ + class DelayInducingInterceptor extends BaseInterceptor + { + private Long delayMillis; + + + public EntryFilteringCursor search( NextInterceptor next, SearchOperationContext opContext ) throws Exception + { + EntryFilteringCursor cursor = next.search( opContext ); + cursor.addEntryFilter( new EntryFilter() { + public boolean accept( SearchingOperationContext operation, ClonedServerEntry result ) throws Exception + { + if ( delayMillis != null ) + { + Thread.sleep( delayMillis ); + } + + return true; + } + }); + return cursor; + } + + + public void setDelayMillis( long delayMillis ) + { + if ( delayMillis <= 0 ) + { + this.delayMillis = null; + } + + this.delayMillis = delayMillis; + } + } + + + private int oldMaxTimeLimit; + private DelayInducingInterceptor delayInterceptor; + + + @Before + public void setUp() throws Exception + { + oldMaxTimeLimit = ldapServer.getMaxTimeLimit(); + delayInterceptor = new DelayInducingInterceptor(); + ldapServer.getDirectoryService().getInterceptorChain().addFirst( delayInterceptor ); + } + + + @After + public void tearDown() throws Exception + { + ldapServer.setMaxTimeLimit( oldMaxTimeLimit ); + ldapServer.getDirectoryService().getInterceptorChain().remove( DelayInducingInterceptor.class.getName() ); + } + + + /** + * 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 + * the client. + */ + @Test ( expected = TimeLimitExceededException.class ) + public void testRequestConstrainedUnlimitByConfiguration() throws Exception + { + ldapServer.setMaxTimeLimit( LdapServer.NO_TIME_LIMIT ); + delayInterceptor.setDelayMillis( 500 ); + + getActorsWithTimeLimit( "(objectClass=*)", 499 ); + } + + + /** + * 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 ) + public void testRequestConstrainedLessThanConfiguration() throws Exception + { + ldapServer.setMaxTimeLimit( 10000 ); // this is in seconds + delayInterceptor.setDelayMillis( 500 ); + + getActorsWithTimeLimit( "(objectClass=*)", 499 ); + } + + + /** + * 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 ) + public void testRequestConstrainedGreaterThanConfiguration() throws Exception + { + ldapServer.setMaxTimeLimit( 1 ); // this is in seconds + delayInterceptor.setDelayMillis( 1100 ); + + getActorsWithTimeLimit( "(objectClass=*)", 100000 ); + } + + + /** + * Sets up the server with limited search time with unlimited request + * time limit. Should work just fine for the administrative user. + */ + @Test + public void testRequestUnlimitedConfigurationLimited() throws Exception + { + ldapServer.setMaxTimeLimit( 1 ); // this is in seconds + delayInterceptor.setDelayMillis( 500 ); + + getActorsWithTimeLimit( "(objectClass=*)", 0 ); + } + + + /** + * Sets up the server with limited search time with unlimited request + * time limit. Should not work for non administrative users. + */ + @Test ( expected = TimeLimitExceededException.class ) + public void testNonAdminRequestUnlimitedConfigurationLimited() throws Exception + { + ldapServer.setMaxTimeLimit( 1 ); // this is in seconds + delayInterceptor.setDelayMillis( 500 ); + + getActorsWithTimeLimitNonAdmin( "(objectClass=*)", 0 ); + } + + + Set getActorsWithTimeLimit( String filter, int timeLimitMillis ) throws Exception + { + DirContext ctx = getWiredContext( ldapServer ); + Set results = new HashSet(); + SearchControls controls = new SearchControls(); + controls.setTimeLimit( timeLimitMillis ); + controls.setSearchScope( SearchControls.ONELEVEL_SCOPE ); + + NamingEnumeration namingEnumeration = ctx.search( "ou=actors,ou=system", filter, controls ); + while( namingEnumeration.hasMore() ) + { + results.add( namingEnumeration.next().getNameInNamespace() ); + } + + return results; + } + + + Set getActorsWithTimeLimitNonAdmin( String filter, int timeLimitMillis ) throws Exception + { + DirContext ctx = getWiredContext( ldapServer, "uid=jblack,ou=actors,ou=system", "secret" ); + Set results = new HashSet(); + SearchControls controls = new SearchControls(); + controls.setTimeLimit( timeLimitMillis ); + controls.setSearchScope( SearchControls.ONELEVEL_SCOPE ); + + NamingEnumeration namingEnumeration = ctx.search( "ou=actors,ou=system", filter, controls ); + while( namingEnumeration.hasMore() ) + { + results.add( namingEnumeration.next().getNameInNamespace() ); + } + + return results; + } +} Modified: directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/suites/StockServerISuite.java URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/suites/StockServerISuite.java?rev=687556&r1=687555&r2=687556&view=diff ============================================================================== --- directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/suites/StockServerISuite.java (original) +++ directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/suites/StockServerISuite.java Wed Aug 20 21:39:48 2008 @@ -45,6 +45,7 @@ import org.apache.directory.server.operations.search.ReferralSearchIT; import org.apache.directory.server.operations.search.SchemaSearchIT; import org.apache.directory.server.operations.search.SearchIT; +import org.apache.directory.server.operations.search.SearchLimitsIT; import org.apache.directory.server.ssl.StartTlsIT; import org.junit.runner.RunWith; import org.junit.runners.Suite; @@ -78,7 +79,8 @@ ReferralSearchIT.class, StartTlsIT.class, ModifyDnReferralIT.class, - PersistentSearchIT.class + PersistentSearchIT.class, + SearchLimitsIT.class } ) @CleanupLevel ( Level.SUITE ) @Mode ( SetupMode.ROLLBACK )