Author: akarasulu
Date: Thu Apr 28 13:54:15 2005
New Revision: 165195
URL: http://svn.apache.org/viewcvs?rev=165195&view=rev
Log:
changes ...
o moving copy of AbstractCoreTest to AbstractServerTest before major changes
o moved test for disabling anon bind to main area since it deals with
seting up all the protocol providers
Added:
directory/apacheds/trunk/main/src/test/
directory/apacheds/trunk/main/src/test/org/
directory/apacheds/trunk/main/src/test/org/apache/
directory/apacheds/trunk/main/src/test/org/apache/ldap/
directory/apacheds/trunk/main/src/test/org/apache/ldap/server/
directory/apacheds/trunk/main/src/test/org/apache/ldap/server/AbstractServerTest.java
- copied, changed from r165059,
directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/AbstractCoreTest.java
directory/apacheds/trunk/main/src/test/org/apache/ldap/server/DisableAnonBindTest.java
- copied, changed from r165167,
directory/apacheds/trunk/core/src/test/org/apache/ldap/server/authn/SimpleAuthenticationTest.java
Modified:
directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/AbstractCoreTest.java
directory/apacheds/trunk/core/src/test/org/apache/ldap/server/authn/SimpleAuthenticationTest.java
directory/apacheds/trunk/main/project.xml
Modified:
directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/AbstractCoreTest.java
URL:
http://svn.apache.org/viewcvs/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/AbstractCoreTest.java?rev=165195&r1=165194&r2=165195&view=diff
==============================================================================
---
directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/AbstractCoreTest.java
(original)
+++
directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/AbstractCoreTest.java
Thu Apr 28 13:54:15 2005
@@ -40,7 +40,7 @@
import java.io.InputStream;
import java.util.Hashtable;
-
+
/**
* A simple testcase for testing JNDI provider functionality.
*
Modified:
directory/apacheds/trunk/core/src/test/org/apache/ldap/server/authn/SimpleAuthenticationTest.java
URL:
http://svn.apache.org/viewcvs/directory/apacheds/trunk/core/src/test/org/apache/ldap/server/authn/SimpleAuthenticationTest.java?rev=165195&r1=165194&r2=165195&view=diff
==============================================================================
---
directory/apacheds/trunk/core/src/test/org/apache/ldap/server/authn/SimpleAuthenticationTest.java
(original)
+++
directory/apacheds/trunk/core/src/test/org/apache/ldap/server/authn/SimpleAuthenticationTest.java
Thu Apr 28 13:54:15 2005
@@ -87,11 +87,6 @@
return;
}
- if ( getName().equals( "test11DisableAnonymousBinds" ) )
- {
- extras.put( EnvKeys.DISABLE_ANONYMOUS, "true" );
- }
-
super.setUp();
}
@@ -322,40 +317,5 @@
env.put( Context.SECURITY_AUTHENTICATION, "simple" );
env.put( Context.INITIAL_CONTEXT_FACTORY,
"org.apache.ldap.server.jndi.ServerContextFactory" );
assertNotNull( new InitialContext( env ) );
- }
-
-
- /**
- * Test to make sure anonymous binds are disabled when going through
- * the wire protocol.
- *
- * @throws Exception if anything goes wrong
- */
- public void test11DisableAnonymousBinds() throws Exception
- {
- // Use the SUN JNDI provider to hit server port and bind as anonymous
-
- final Hashtable env = new Hashtable();
-
- env.put( Context.PROVIDER_URL, "ldap://localhost:" + port +
"/ou=system" );
-
- env.put( Context.SECURITY_AUTHENTICATION, "none" );
-
- env.put( Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.ldap.LdapCtxFactory" );
-
- InitialContext ctx = null;
-
- try
- {
- ctx = new InitialContext( env );
-
- fail( "If anonymous binds are disabled we should never get here!"
);
- }
- catch ( NoPermissionException e )
- {
- assertNull( ctx );
-
- assertNotNull( e );
- }
}
}
Modified: directory/apacheds/trunk/main/project.xml
URL:
http://svn.apache.org/viewcvs/directory/apacheds/trunk/main/project.xml?rev=165195&r1=165194&r2=165195&view=diff
==============================================================================
--- directory/apacheds/trunk/main/project.xml (original)
+++ directory/apacheds/trunk/main/project.xml Thu Apr 28 13:54:15 2005
@@ -51,6 +51,12 @@
<url>http://jakarta.apache.org/commons/collections</url>
</dependency>
<dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ <version>1.0</version>
+ <url>http://jakarta.apache.org/commons/io</url>
+ </dependency>
+ <dependency>
<groupId>commons-primitives</groupId>
<artifactId>commons-primitives</artifactId>
<version>20041207.202534</version>
Copied:
directory/apacheds/trunk/main/src/test/org/apache/ldap/server/AbstractServerTest.java
(from r165059,
directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/AbstractCoreTest.java)
URL:
http://svn.apache.org/viewcvs/directory/apacheds/trunk/main/src/test/org/apache/ldap/server/AbstractServerTest.java?p2=directory/apacheds/trunk/main/src/test/org/apache/ldap/server/AbstractServerTest.java&p1=directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/AbstractCoreTest.java&r1=165059&r2=165195&rev=165195&view=diff
==============================================================================
---
directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/AbstractCoreTest.java
(original)
+++
directory/apacheds/trunk/main/src/test/org/apache/ldap/server/AbstractServerTest.java
Thu Apr 28 13:54:15 2005
@@ -47,7 +47,7 @@
* @author <a href="mailto:[email protected]">Apache Directory
Project</a>
* @version $Rev$
*/
-public abstract class AbstractCoreTest extends TestCase
+public abstract class AbstractServerTest extends TestCase
{
/** the context root for the system partition */
protected LdapContext sysRoot;
Copied:
directory/apacheds/trunk/main/src/test/org/apache/ldap/server/DisableAnonBindTest.java
(from r165167,
directory/apacheds/trunk/core/src/test/org/apache/ldap/server/authn/SimpleAuthenticationTest.java)
URL:
http://svn.apache.org/viewcvs/directory/apacheds/trunk/main/src/test/org/apache/ldap/server/DisableAnonBindTest.java?p2=directory/apacheds/trunk/main/src/test/org/apache/ldap/server/DisableAnonBindTest.java&p1=directory/apacheds/trunk/core/src/test/org/apache/ldap/server/authn/SimpleAuthenticationTest.java&r1=165167&r2=165195&rev=165195&view=diff
==============================================================================
---
directory/apacheds/trunk/core/src/test/org/apache/ldap/server/authn/SimpleAuthenticationTest.java
(original)
+++
directory/apacheds/trunk/main/src/test/org/apache/ldap/server/DisableAnonBindTest.java
Thu Apr 28 13:54:15 2005
@@ -14,22 +14,12 @@
* limitations under the License.
*
*/
-package org.apache.ldap.server.authn;
+package org.apache.ldap.server;
-import org.apache.ldap.common.exception.LdapConfigurationException;
-import org.apache.ldap.common.exception.LdapNoPermissionException;
-import org.apache.ldap.common.util.ArrayUtils;
-import org.apache.ldap.server.AbstractCoreTest;
import org.apache.ldap.server.jndi.EnvKeys;
-import org.apache.mina.util.AvailablePortFinder;
import javax.naming.*;
-import javax.naming.directory.Attribute;
-import javax.naming.directory.Attributes;
-import javax.naming.directory.DirContext;
-import javax.naming.directory.InitialDirContext;
-import javax.naming.ldap.InitialLdapContext;
import java.io.File;
import java.io.IOException;
import java.util.Hashtable;
@@ -42,52 +32,26 @@
* @author <a href="mailto:[email protected]">Apache Directory
Project</a>
* @version $Rev$
*/
-public class SimpleAuthenticationTest extends AbstractCoreTest
+public class DisableAnonBindTest extends AbstractServerTest
{
/**
* Cleans up old database files on creation.
* @throws IOException
*/
- public SimpleAuthenticationTest() throws IOException
+ public DisableAnonBindTest() throws IOException
{
- doDelete( new File( "target" + File.separator + "eve" ) );
+ doDelete( new File( "target" + File.separator + "server" ) );
}
/**
* Customizes setup for each test case.
*
- * <ul>
- * <li>sets doDelete to false for test1AdminAccountCreation</li>
- * <li>sets doDelete to false for test2AccountExistsOnRestart</li>
- * <li>sets doDelete to true for all other cases</li>
- * <li>bypasses normal setup for test5BuildDbNoPassWithPrincAuthNone</li>
- * <li>bypasses normal setup for test4BuildDbNoPassNoPrincAuthNone</li>
- * <li>bypasses normal setup for test6BuildDbNoPassNotAdminPrinc</li>
- * </ul>
- *
* @throws Exception
*/
protected void setUp() throws Exception
{
- if ( getName().equals( "test1AdminAccountCreation" ) ||
- getName().equals( "test2AccountExistsOnRestart" ) )
- {
- super.doDelete = false;
- }
- else
- {
- super.doDelete = true;
- }
-
- if ( getName().equals( "test5BuildDbNoPassWithPrincAuthNone" ) ||
- getName().equals( "test6BuildDbNoPassNotAdminPrinc" ) ||
- getName().equals( "test4BuildDbNoPassNoPrincAuthNone" ) )
- {
- return;
- }
-
- if ( getName().equals( "test11DisableAnonymousBinds" ) )
+ if ( getName().equals( "testDisableAnonymousBinds" ) )
{
extras.put( EnvKeys.DISABLE_ANONYMOUS, "true" );
}
@@ -97,241 +61,12 @@
/**
- * Checks all attributes of the admin account entry minus the userPassword
- * attribute.
- *
- * @param attrs the entries attributes
- */
- protected void performAdminAccountChecks( Attributes attrs )
- {
- assertTrue( attrs.get( "objectClass" ).contains( "top" ) );
- assertTrue( attrs.get( "objectClass" ).contains( "person" ) );
- assertTrue( attrs.get( "objectClass" ).contains(
"organizationalPerson" ) );
- assertTrue( attrs.get( "objectClass" ).contains( "inetOrgPerson" ) );
- assertTrue( attrs.get( "displayName" ).contains( "Directory Superuser"
) );
- }
-
-
- /**
- * Check the creation of the admin account.
- *
- * @throws NamingException if there are failures
- */
- public void test1AdminAccountCreation() throws NamingException
- {
- DirContext ctx = ( DirContext ) sysRoot.lookup( "uid=admin" );
- Attributes attrs = ctx.getAttributes( "" );
- performAdminAccountChecks( attrs );
- assertTrue( ArrayUtils.isEquals( attrs.get( "userPassword" ).get(),
"secret".getBytes() ));
- }
-
-
- /**
- * Check the creation of the admin account even after a restart.
- *
- * @throws NamingException if there are failures
- */
- public void test2AccountExistsOnRestart() throws NamingException
- {
- DirContext ctx = ( DirContext ) sysRoot.lookup( "uid=admin" );
- Attributes attrs = ctx.getAttributes( "" );
-
- performAdminAccountChecks( attrs );
- assertTrue( ArrayUtils.isEquals( attrs.get( "userPassword" ).get(),
"secret".getBytes() ));
- }
-
-
- public void test3UseAkarasulu() throws NamingException
- {
- Hashtable env = new Hashtable();
- env.put( Context.PROVIDER_URL, "ou=system" );
- env.put( Context.SECURITY_PRINCIPAL,
"uid=akarasulu,ou=users,ou=system" );
- env.put( Context.SECURITY_CREDENTIALS, "test" );
- env.put( Context.SECURITY_AUTHENTICATION, "simple" );
- env.put( Context.INITIAL_CONTEXT_FACTORY,
"org.apache.ldap.server.jndi.ServerContextFactory" );
- InitialDirContext ic = new InitialDirContext( env );
- Attributes attrs = ic.getAttributes( "uid=akarasulu,ou=users" );
- Attribute ou = attrs.get( "ou" );
- assertTrue( ou.contains( "Engineering" ) );
- assertTrue( ou.contains( "People" ) );
-
- Attribute objectClass = attrs.get( "objectClass" );
- assertTrue( objectClass.contains( "top" ) );
- assertTrue( objectClass.contains( "person" ) );
- assertTrue( objectClass.contains( "organizationalPerson" ) );
- assertTrue( objectClass.contains( "inetOrgPerson" ) );
-
- assertTrue( attrs.get( "telephonenumber" ).contains( "+1 408 555 4798"
) );
- assertTrue( attrs.get( "uid" ).contains( "akarasulu" ) );
- assertTrue( attrs.get( "givenname" ).contains( "Alex" ) );
- assertTrue( attrs.get( "mail" ).contains( "[EMAIL PROTECTED]" ) );
- assertTrue( attrs.get( "l" ).contains( "Bogusville" ) );
- assertTrue( attrs.get( "sn" ).contains( "Karasulu" ) );
- assertTrue( attrs.get( "cn" ).contains( "Alex Karasulu" ) );
- assertTrue( attrs.get( "facsimiletelephonenumber" ).contains( "+1 408
555 9751" ) );
- assertTrue( attrs.get( "roomnumber" ).contains( "4612" ) );
- }
-
-
- /**
- * Tests to make sure we throw an error when
Context.SECURITY_AUTHENTICATION
- * is set to "none" when trying to bootstrap the system. Only the admin
- * user is allowed to bootstrap.
- *
- * @throws Exception if anything goes wrong
- */
- public void test4BuildDbNoPassNoPrincAuthNone() throws Exception
- {
- // clean out the database
- tearDown();
- doDelete( new File( "target" + File.separator + "eve" ) );
- Hashtable env = new Hashtable();
- env.put( Context.SECURITY_AUTHENTICATION, "none" );
- env.put( EnvKeys.DISABLE_ANONYMOUS, "true" );
-
- int port = AvailablePortFinder.getNextAvailable( 1024 );
-
- env.put( EnvKeys.LDAP_PORT, String.valueOf( port ) );
-
- try
- {
- setSysRoot( env );
- fail( "should not get here due to exception" );
- }
- catch( LdapNoPermissionException e )
- {
- }
-
- // ok this should start up the system now as admin
- Hashtable anonymous = new Hashtable();
-
- anonymous.put( EnvKeys.LDAP_PORT, String.valueOf( port ) );
-
- InitialLdapContext ctx = ( InitialLdapContext ) setSysRoot( anonymous
);
- assertNotNull( ctx );
-
- // now go in as anonymous user and we should be wh
- env.put( Context.PROVIDER_URL, "ou=system" );
- env.put( Context.INITIAL_CONTEXT_FACTORY,
"org.apache.ldap.server.jndi.ServerContextFactory" );
-
- InitialLdapContext initial = new InitialLdapContext( env, null );
-
- try
- {
- ctx = ( InitialLdapContext ) initial.lookup( "uid=admin" );
- fail( "should not get here due to exception cuz anonymous user is "
- + "not allowed read access to the admin account entry" );
- }
- catch( LdapConfigurationException e )
- {
- }
- catch( LdapNoPermissionException e )
- {
- }
- }
-
-
- /**
- * Tests to make sure we throw an error when
Context.SECURITY_AUTHENTICATION
- * is set to "none" when trying to bootstrap the system even when the
- * principal is set to the admin user. Only the admin user is allowed to
- * bootstrap. This is a configuration issue or a nonsense set of property
- * values.
- *
- * @throws Exception if anything goes wrong
- */
- public void test5BuildDbNoPassWithPrincAuthNone() throws Exception
- {
- // clean out the database
- tearDown();
- doDelete( new File( "target" + File.separator + "eve" ) );
- Hashtable env = new Hashtable();
- env.put( Context.SECURITY_AUTHENTICATION, "none" );
- env.put( Context.SECURITY_PRINCIPAL, "uid=admin,ou=system" );
-
- try
- {
- setSysRoot( env );
- fail( "should not get here due to exception" );
- }
- catch( ConfigurationException e )
- {
- }
- }
-
-
- /**
- * Tests to make sure we throw an error when
Context.SECURITY_AUTHENTICATION
- * is set to "simple" when trying to bootstrap the system but the admin is
- * not the principal. Only the admin user is allowed to bootstrap.
- * Subsequent calls can 'bind' (authenticate in our case since there is no
- * network connection) anonymously though.
- *
- * @throws Exception if anything goes wrong
- */
- public void test6BuildDbNoPassNotAdminPrinc() throws Exception
- {
- // clean out the database
- tearDown();
- doDelete( new File( "target" + File.separator + "eve" ) );
- Hashtable env = new Hashtable();
- env.put( Context.SECURITY_AUTHENTICATION, "simple" );
- env.put( Context.SECURITY_PRINCIPAL,
"uid=akarasulu,ou=users,ou=system" );
-
- try
- {
- setSysRoot( env );
- fail( "should not get here due to exception" );
- }
- catch( ConfigurationException e )
- {
- }
- }
-
-
- /**
- * Tests to make sure we can authenticate after the database has already
- * been started by the admin user when simple authentication is in effect.
- *
- * @throws Exception if anything goes wrong
- */
- public void test8PassPrincAuthTypeSimple() throws Exception
- {
- Hashtable env = new Hashtable();
- env.put( Context.PROVIDER_URL, "ou=system" );
- env.put( Context.SECURITY_PRINCIPAL, "uid=admin,ou=system" );
- env.put( Context.SECURITY_CREDENTIALS, "secret" );
- env.put( Context.SECURITY_AUTHENTICATION, "simple" );
- env.put( Context.INITIAL_CONTEXT_FACTORY,
"org.apache.ldap.server.jndi.ServerContextFactory" );
- assertNotNull( new InitialContext( env ) );
- }
-
-
- /**
- * Checks to see if we can authenticate as a test user after the admin
fires
- * up and builds the the system database.
- *
- * @throws Exception if anything goes wrong
- */
- public void test10TestNonAdminUser() throws Exception
- {
- Hashtable env = new Hashtable();
- env.put( Context.PROVIDER_URL, "ou=system" );
- env.put( Context.SECURITY_PRINCIPAL,
"uid=akarasulu,ou=users,ou=system" );
- env.put( Context.SECURITY_CREDENTIALS, "test" );
- env.put( Context.SECURITY_AUTHENTICATION, "simple" );
- env.put( Context.INITIAL_CONTEXT_FACTORY,
"org.apache.ldap.server.jndi.ServerContextFactory" );
- assertNotNull( new InitialContext( env ) );
- }
-
-
- /**
* Test to make sure anonymous binds are disabled when going through
* the wire protocol.
*
* @throws Exception if anything goes wrong
*/
- public void test11DisableAnonymousBinds() throws Exception
+ public void testDisableAnonymousBinds() throws Exception
{
// Use the SUN JNDI provider to hit server port and bind as anonymous