You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by ak...@apache.org on 2008/08/05 03:08:59 UTC
svn commit: r682556 - in /directory/apacheds/branches/bigbang:
protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/
server-integ/src/test/java/org/apache/directory/server/operations/compare/
server-integ/src/test/java/org/apache...
Author: akarasulu
Date: Mon Aug 4 18:08:58 2008
New Revision: 682556
URL: http://svn.apache.org/viewvc?rev=682556&view=rev
Log:
moving, consolidating and adapting tests from server-unit to server-integ
o removed what tests were valid from DelITest into DeleteIT and deleted it
o no valid tests in DeleteIllegalDNITest which had search test - moved
test into SearchITest and deleted the test class
o committing code in new delete handler forgoten before in last commit
o moving some compare tests from server unit to server integ
Added:
directory/apacheds/branches/bigbang/server-integ/src/test/java/org/apache/directory/server/operations/compare/MatchingRuleCompareTest.java
- copied, changed from r682443, directory/apacheds/branches/bigbang/server-unit/src/test/java/org/apache/directory/server/MatchingRuleCompareTest.java
Removed:
directory/apacheds/branches/bigbang/server-unit/src/test/java/org/apache/directory/server/DelITest.java
directory/apacheds/branches/bigbang/server-unit/src/test/java/org/apache/directory/server/DeleteIllegalDNITest.java
directory/apacheds/branches/bigbang/server-unit/src/test/java/org/apache/directory/server/MatchingRuleCompareTest.java
Modified:
directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/NewDeleteHandler.java
directory/apacheds/branches/bigbang/server-integ/src/test/java/org/apache/directory/server/operations/compare/CompareIT.java
directory/apacheds/branches/bigbang/server-integ/src/test/java/org/apache/directory/server/operations/delete/DeleteIT.java
directory/apacheds/branches/bigbang/server-unit/src/test/java/org/apache/directory/server/MiscTest.java
directory/apacheds/branches/bigbang/server-unit/src/test/java/org/apache/directory/server/SearchITest.java
Modified: directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/NewDeleteHandler.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/NewDeleteHandler.java?rev=682556&r1=682555&r2=682556&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/NewDeleteHandler.java (original)
+++ directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/NewDeleteHandler.java Mon Aug 4 18:08:58 2008
@@ -20,17 +20,12 @@
package org.apache.directory.server.newldap.handlers;
-import javax.naming.NamingException;
-import javax.naming.ReferralException;
-
+import org.apache.directory.server.core.entry.ClonedServerEntry;
import org.apache.directory.server.newldap.LdapSession;
-import org.apache.directory.shared.ldap.exception.LdapException;
import org.apache.directory.shared.ldap.message.DeleteRequest;
import org.apache.directory.shared.ldap.message.LdapResult;
-import org.apache.directory.shared.ldap.message.ReferralImpl;
import org.apache.directory.shared.ldap.message.ResultCodeEnum;
import org.apache.directory.shared.ldap.name.LdapDN;
-import org.apache.directory.shared.ldap.util.ExceptionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -42,16 +37,15 @@
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
* @version $Rev: 664302 $
*/
-public class NewDeleteHandler extends LdapRequestHandler<DeleteRequest>
+public class NewDeleteHandler extends SingleReplyRequestHandler<DeleteRequest>
{
private static final Logger LOG = LoggerFactory.getLogger( NewDeleteHandler.class );
- /** Speedup for logs */
- private static final boolean IS_DEBUG = LOG.isDebugEnabled();
-
- public void handle( LdapSession session, DeleteRequest req ) throws Exception
+ public void handleIgnoringReferrals( LdapSession session, LdapDN reqTargetDn,
+ ClonedServerEntry entry, DeleteRequest req )
{
+ LOG.debug( "Handling request while ignoring referrals: {}", req );
LdapResult result = req.getResultResponse().getLdapResult();
try
@@ -60,50 +54,9 @@
result.setResultCode( ResultCodeEnum.SUCCESS );
session.getIoSession().write( req.getResultResponse() );
}
- catch ( ReferralException e )
- {
- ReferralImpl refs = new ReferralImpl();
- result.setReferral( refs );
- result.setResultCode( ResultCodeEnum.REFERRAL );
- result.setErrorMessage( "Encountered referral attempting to handle delete request." );
- /* coming up null causing a NPE */
- // result.setMatchedDn( e.getResolvedName().toString() );
- do
- {
- refs.addLdapUrl( ( String ) e.getReferralInfo() );
- }
- while ( e.skipReferral() );
- session.getIoSession().write( req.getResultResponse() );
- }
- catch ( NamingException e )
+ catch ( Exception e )
{
- String msg = "failed to delete entry " + req.getName() + ": " + e.getMessage();
-
- if ( IS_DEBUG )
- {
- msg += ":\n" + ExceptionUtils.getStackTrace( e );
- }
-
- ResultCodeEnum code;
- if ( e instanceof LdapException )
- {
- code = ( ( LdapException ) e ).getResultCode();
- }
- else
- {
- code = ResultCodeEnum.getBestEstimate( e, req.getType() );
- }
-
- result.setResultCode( code );
- result.setErrorMessage( msg );
- if ( ( e.getResolvedName() != null )
- && ( ( code == ResultCodeEnum.NO_SUCH_OBJECT ) || ( code == ResultCodeEnum.ALIAS_PROBLEM )
- || ( code == ResultCodeEnum.INVALID_DN_SYNTAX ) || ( code == ResultCodeEnum.ALIAS_DEREFERENCING_PROBLEM ) ) )
- {
- result.setMatchedDn( (LdapDN)e.getResolvedName() );
- }
-
- session.getIoSession().write( req.getResultResponse() );
+ handleException( session, req, e );
}
}
}
\ No newline at end of file
Modified: directory/apacheds/branches/bigbang/server-integ/src/test/java/org/apache/directory/server/operations/compare/CompareIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/server-integ/src/test/java/org/apache/directory/server/operations/compare/CompareIT.java?rev=682556&r1=682555&r2=682556&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/server-integ/src/test/java/org/apache/directory/server/operations/compare/CompareIT.java (original)
+++ directory/apacheds/branches/bigbang/server-integ/src/test/java/org/apache/directory/server/operations/compare/CompareIT.java Mon Aug 4 18:08:58 2008
@@ -247,6 +247,31 @@
/**
+ * Check that operation are not executed if we are now allowed to bind
+ * anonymous
+ * @throws LDAPException
+ */
+ @Test
+ public void testCompareWithoutAuthentication() throws LDAPException
+ {
+ ldapServer.getDirectoryService().setAllowAnonymousAccess( false );
+ LDAPConnection conn = new LDAPConnection();
+ conn.connect( "localhost", ldapServer.getIpPort() );
+ LDAPAttribute attr = new LDAPAttribute( "uid", "admin" );
+
+ try
+ {
+ conn.compare( "uid=admin,ou=system", attr );
+ fail( "Compare success without authentication" );
+ }
+ catch ( LDAPException e )
+ {
+ assertEquals( "no permission exception", 50, e.getLDAPResultCode() );
+ }
+ }
+
+
+ /**
* Tests compare operation on normal and referral entries without the
* ManageDsaIT control using JNDI while chasing referrals instead of
* the Netscape API. Referrals are sent back to the client with a
Copied: directory/apacheds/branches/bigbang/server-integ/src/test/java/org/apache/directory/server/operations/compare/MatchingRuleCompareTest.java (from r682443, directory/apacheds/branches/bigbang/server-unit/src/test/java/org/apache/directory/server/MatchingRuleCompareTest.java)
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/server-integ/src/test/java/org/apache/directory/server/operations/compare/MatchingRuleCompareTest.java?p2=directory/apacheds/branches/bigbang/server-integ/src/test/java/org/apache/directory/server/operations/compare/MatchingRuleCompareTest.java&p1=directory/apacheds/branches/bigbang/server-unit/src/test/java/org/apache/directory/server/MatchingRuleCompareTest.java&r1=682443&r2=682556&rev=682556&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/server-unit/src/test/java/org/apache/directory/server/MatchingRuleCompareTest.java (original)
+++ directory/apacheds/branches/bigbang/server-integ/src/test/java/org/apache/directory/server/operations/compare/MatchingRuleCompareTest.java Mon Aug 4 18:08:58 2008
@@ -17,24 +17,25 @@
* under the License.
*
*/
-package org.apache.directory.server;
+package org.apache.directory.server.operations.compare;
-import java.util.Hashtable;
-
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
-import javax.naming.directory.Attribute;
-import javax.naming.directory.Attributes;
import javax.naming.directory.DirContext;
import javax.naming.directory.SearchControls;
import javax.naming.directory.SearchResult;
-import javax.naming.ldap.InitialLdapContext;
-import javax.naming.ldap.LdapContext;
-import org.apache.directory.server.unit.AbstractServerTest;
-import org.apache.directory.shared.ldap.message.AttributeImpl;
-import org.apache.directory.shared.ldap.message.AttributesImpl;
+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.integ.ServerIntegrationUtils;
+import org.apache.directory.server.integ.SiRunner;
+import org.apache.directory.server.newldap.LdapServer;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import static org.junit.Assert.assertEquals;
/**
@@ -45,9 +46,28 @@
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
* @version $Rev$
*/
-public class MatchingRuleCompareTest extends AbstractServerTest
+@RunWith ( SiRunner.class )
+@CleanupLevel ( Level.SUITE )
+@ApplyLdifs( {
+ // Entry # 1
+ "dn: cn=Tori Amos,ou=system\n" +
+ "objectClass: person\n" +
+ "objectClass: top\n" +
+ "telephoneNumber: 1234567890\n" +
+ "userPassword: Secret1!\n" +
+ "cn: Tori Amos\n" +
+ "sn: Amos\n\n" +
+ // Entry # 2
+ "dn: cn=Artists,ou=system\n" +
+ "objectClass: groupOfNames\n" +
+ "objectClass: top\n" +
+ "cn: Artists\n" +
+ "member: cn=Tori Amos,ou=system\n\n"
+ }
+)
+public class MatchingRuleCompareTest
{
- private LdapContext ctx = null;
+ public static LdapServer ldapServer;
public static final String PERSON_CN = "Tori Amos";
public static final String PERSON_SN = "Amos";
@@ -59,85 +79,16 @@
public static final String GROUP_RDN = "cn=" + GROUP_CN;
- protected Attributes getPersonAttributes( String sn, String cn )
- {
- Attributes attributes = new AttributesImpl();
- Attribute attribute = new AttributeImpl( "objectClass" );
- attribute.add( "top" );
- attribute.add( "person" );
- attributes.put( attribute );
- attributes.put( "cn", cn );
- attributes.put( "sn", sn );
-
- return attributes;
- }
-
-
- protected Attributes getGroupOfNamesAttributes( String cn, String member )
- {
- Attributes attributes = new AttributesImpl();
- Attribute attribute = new AttributeImpl( "objectClass" );
- attribute.add( "top" );
- attribute.add( "groupOfNames" );
- attributes.put( attribute );
- attributes.put( "cn", cn );
- attributes.put( "member", member );
-
- return attributes;
- }
-
-
- /**
- * Create context, a person entry and a group.
- */
- public void setUp() throws Exception
- {
- super.setUp();
-
- Hashtable<String, Object> env = new Hashtable<String, Object>();
- env.put( "java.naming.factory.initial", "com.sun.jndi.ldap.LdapCtxFactory" );
- env.put( "java.naming.provider.url", "ldap://localhost:" + port + "/ou=system" );
- env.put( "java.naming.security.principal", "uid=admin,ou=system" );
- env.put( "java.naming.security.credentials", "secret" );
- env.put( "java.naming.security.authentication", "simple" );
-
- ctx = new InitialLdapContext( env, null );
- assertNotNull( ctx );
-
- // Create a person
- Attributes attributes = this.getPersonAttributes( PERSON_SN, PERSON_CN );
- attributes.put( "telephoneNumber", PERSON_TELEPHONE );
- attributes.put( "userPassword", PERSON_PWD );
- ctx.createSubcontext( PERSON_RDN, attributes );
-
- // Create a group
- DirContext member = ( DirContext ) ctx.lookup( PERSON_RDN );
- attributes = this.getGroupOfNamesAttributes( GROUP_CN, member.getNameInNamespace() );
- ctx.createSubcontext( GROUP_RDN, attributes );
- }
-
-
- /**
- * Remove entries and close context.
- */
- public void tearDown() throws Exception
- {
- ctx.unbind( PERSON_RDN );
- ctx.unbind( GROUP_RDN );
-
- ctx.close();
-
- super.tearDown();
- }
-
-
/**
* Compare with caseIgnoreMatch matching rule.
*
* @throws NamingException
*/
- public void testCaseIgnoreMatch() throws NamingException
+ @Test
+ public void testCaseIgnoreMatch() throws Exception
{
+ DirContext ctx = ( DirContext ) ServerIntegrationUtils.getWiredContext( ldapServer ).lookup( "ou=system" );
+
// Setting up search controls for compare op
SearchControls ctls = new SearchControls();
ctls.setReturningAttributes( new String[]
@@ -240,8 +191,11 @@
*
* @throws NamingException
*/
- public void testDistinguishedNameMatch() throws NamingException
+ @Test
+ public void testDistinguishedNameMatch() throws Exception
{
+ DirContext ctx = ( DirContext ) ServerIntegrationUtils.getWiredContext( ldapServer ).lookup( "ou=system" );
+
// determine member DN of person
DirContext member = ( DirContext ) ctx.lookup( PERSON_RDN );
String memberDN = member.getNameInNamespace();
@@ -270,5 +224,4 @@
enumeration.close();
}
}
-
}
Modified: directory/apacheds/branches/bigbang/server-integ/src/test/java/org/apache/directory/server/operations/delete/DeleteIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/server-integ/src/test/java/org/apache/directory/server/operations/delete/DeleteIT.java?rev=682556&r1=682555&r2=682556&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/server-integ/src/test/java/org/apache/directory/server/operations/delete/DeleteIT.java (original)
+++ directory/apacheds/branches/bigbang/server-integ/src/test/java/org/apache/directory/server/operations/delete/DeleteIT.java Mon Aug 4 18:08:58 2008
@@ -23,6 +23,7 @@
import static org.apache.directory.server.integ.ServerIntegrationUtils.getWiredConnection;
import static org.apache.directory.server.integ.ServerIntegrationUtils.getWiredContextThrowOnRefferal;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import javax.naming.NameNotFoundException;
@@ -288,4 +289,26 @@
conn.disconnect();
}
+
+
+
+ /**
+ * Try to delete an entry with invalid DN. Expected result code is 32
+ * (NO_SUCH_OBJECT) or 34 (INVALID_DN_SYNTAX).
+ */
+ public void testDeleteWithIllegalName() throws Exception
+ {
+ LDAPConnection conn = getWiredConnection( ldapServer );
+
+ try
+ {
+ conn.delete("This is an illegal name,dc=example,dc=com" );
+ fail( "deletion should fail" );
+ }
+ catch ( LDAPException e )
+ {
+ assertTrue( e.getLDAPResultCode() == LDAPException.INVALID_DN_SYNTAX ||
+ e.getLDAPResultCode() == LDAPException.NO_SUCH_OBJECT );
+ }
+ }
}
Modified: directory/apacheds/branches/bigbang/server-unit/src/test/java/org/apache/directory/server/MiscTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/server-unit/src/test/java/org/apache/directory/server/MiscTest.java?rev=682556&r1=682555&r2=682556&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/server-unit/src/test/java/org/apache/directory/server/MiscTest.java (original)
+++ directory/apacheds/branches/bigbang/server-unit/src/test/java/org/apache/directory/server/MiscTest.java Mon Aug 4 18:08:58 2008
@@ -37,10 +37,6 @@
import javax.naming.directory.SearchResult;
import javax.naming.ldap.InitialLdapContext;
-import netscape.ldap.LDAPAttribute;
-import netscape.ldap.LDAPConnection;
-import netscape.ldap.LDAPException;
-
import org.apache.directory.server.core.entry.DefaultServerEntry;
import org.apache.directory.server.core.entry.ServerEntry;
import org.apache.directory.server.core.partition.Partition;
@@ -137,30 +133,6 @@
/**
- * Check that operation are not executed if we are now allowed to bind
- * anonymous
- * @throws LDAPException
- */
- @Test
- public void testCompareWithoutAuthentication() throws LDAPException
- {
- directoryService.setAllowAnonymousAccess( false );
- LDAPConnection conn = new LDAPConnection();
- conn.connect( "localhost", super.port );
- LDAPAttribute attr = new LDAPAttribute( "uid", "admin" );
- try
- {
- conn.compare( "uid=admin,ou=system", attr );
- fail( "Compare success without authentication" );
- }
- catch ( LDAPException e )
- {
- assertEquals( "no permission exception", 50, e.getLDAPResultCode() );
- }
- }
-
-
- /**
* Test to make sure anonymous binds are disabled when going through
* the wire protocol.
*
@@ -420,6 +392,7 @@
private static final long serialVersionUID = 1L;
+ @SuppressWarnings("unused")
public String getType()
{
return "1.1.1.1";
@@ -431,12 +404,14 @@
}
+ @SuppressWarnings("unused")
public byte[] getValue()
{
return new byte[0];
}
+ @SuppressWarnings("unused")
public void setValue( byte[] value )
{
}
Modified: directory/apacheds/branches/bigbang/server-unit/src/test/java/org/apache/directory/server/SearchITest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/server-unit/src/test/java/org/apache/directory/server/SearchITest.java?rev=682556&r1=682555&r2=682556&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/server-unit/src/test/java/org/apache/directory/server/SearchITest.java (original)
+++ directory/apacheds/branches/bigbang/server-unit/src/test/java/org/apache/directory/server/SearchITest.java Mon Aug 4 18:08:58 2008
@@ -25,6 +25,7 @@
import java.util.Hashtable;
import java.util.Set;
+import javax.naming.InvalidNameException;
import javax.naming.NameNotFoundException;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
@@ -182,7 +183,55 @@
ctx.createSubcontext( HEATHER_RDN, heather );
}
+
+ public void testSearch() throws Exception
+ {
+ LdapContext ctx = getWiredContext();
+ SearchControls controls = new SearchControls();
+ controls.setSearchScope( SearchControls.OBJECT_SCOPE );
+ controls.setTimeLimit( 10 );
+
+ try
+ {
+ ctx.search( "myBadDN", "(objectClass=*)", controls );
+ fail(); // We should get an exception here
+ }
+ catch ( InvalidNameException ine )
+ {
+ // Expected.
+ }
+ catch ( NamingException ne )
+ {
+ fail();
+ }
+ catch( Exception e )
+ {
+ fail();
+ }
+
+ try
+ {
+ controls = new SearchControls();
+ controls.setSearchScope( SearchControls.ONELEVEL_SCOPE );
+ controls.setTimeLimit( 10 );
+
+ NamingEnumeration<SearchResult> result = ctx.search( "ou=system", "(objectClass=*)", controls );
+
+ assertTrue( result.hasMore() );
+ }
+ catch ( InvalidNameException ine )
+ {
+ fail();
+ // Expected.
+ }
+ catch ( NamingException ne )
+ {
+ fail();
+ }
+ }
+
+
/**
* Remove person entry and close context.
*/