Author: akarasulu Date: Sun Oct 31 19:34:39 2004 New Revision: 56191 Added: incubator/directory/eve/trunk/backend/core/src/test/org/apache/eve/jndi/ImportConfirmationTest.java Modified: incubator/directory/eve/trunk/backend/core/src/test/org/apache/eve/jndi/SimpleAuthenticationTest.java Log: Changes ...
o added tests to confirm authentication works for non-admin users o added test to confirm the creation of system.ldif file entries Added: incubator/directory/eve/trunk/backend/core/src/test/org/apache/eve/jndi/ImportConfirmationTest.java ============================================================================== --- (empty file) +++ incubator/directory/eve/trunk/backend/core/src/test/org/apache/eve/jndi/ImportConfirmationTest.java Sun Oct 31 19:34:39 2004 @@ -0,0 +1,94 @@ +/* + * Copyright 2004 The Apache Software Foundation + * + * Licensed 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.eve.jndi; + + +import java.io.InputStream; + +import javax.naming.directory.Attributes; +import javax.naming.directory.Attribute; +import javax.naming.Name; +import javax.naming.NamingEnumeration; +import javax.naming.NamingException; + +import org.apache.ldap.common.ldif.LdifParser; +import org.apache.ldap.common.ldif.LdifParserImpl; +import org.apache.ldap.common.ldif.LdifIterator; +import org.apache.ldap.common.message.LockableAttributesImpl; +import org.apache.ldap.common.name.LdapName; +import org.apache.eve.exception.EveConfigurationException; + + +/** + * Tests to make sure the system.ldif entries were properly imported into the + * system partition. + * + * @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a> + * @version $Rev$ + */ +public class ImportConfirmationTest extends AbstractJndiTest +{ + /** + * Tests to make sure we can authenticate after the database has already + * been build as the admin user when simple authentication is in effect. + * + * @throws Exception if anything goes wrong + */ + public void testConfirmImportedEntries() throws Exception + { + InputStream in = ( InputStream ) getClass().getResourceAsStream( "system.ldif" ); + LdifParser parser = new LdifParserImpl(); + + try + { + LdifIterator iterator = new LdifIterator( in ); + while ( iterator.hasNext() ) + { + Attributes ldifAttributes = new LockableAttributesImpl(); + String ldif = ( String ) iterator.next(); + parser.parse( ldifAttributes, ldif ); + Name dn = new LdapName( ( String ) ldifAttributes.remove( "dn" ).get() ); + + dn.remove( 0 ); + Attributes entry = sysRoot.getAttributes( dn ); + + assertNotNull( entry ); + NamingEnumeration ids = ldifAttributes.getIDs(); + while ( ids.hasMore() ) + { + String id = ( String ) ids.next(); + Attribute entryAttribute = entry.get( id ); + Attribute ldifAttribute = entry.get( id ); + assertNotNull( ldifAttribute ); + assertNotNull( entryAttribute ); + + for ( int ii = 0; ii < ldifAttribute.size(); ii++ ) + { + assertTrue( entryAttribute.contains( ldifAttribute.get( ii ) ) ); + } + } + } + } + catch ( Exception e ) + { + String msg = "failed while trying to parse system ldif file"; + NamingException ne = new EveConfigurationException( msg ); + ne.setRootCause( e ); + throw ne; + } + } +} Modified: incubator/directory/eve/trunk/backend/core/src/test/org/apache/eve/jndi/SimpleAuthenticationTest.java ============================================================================== --- incubator/directory/eve/trunk/backend/core/src/test/org/apache/eve/jndi/SimpleAuthenticationTest.java (original) +++ incubator/directory/eve/trunk/backend/core/src/test/org/apache/eve/jndi/SimpleAuthenticationTest.java Sun Oct 31 19:34:39 2004 @@ -303,9 +303,8 @@ /** - * Tests to make sure we throw an error when Context.SECURITY_AUTHENTICATION - * is set to "none" when trying to get a context from an already - * bootstrapped system when anonymous users are not turned on. + * Tests to make sure we can authenticate after the database has already + * been build as the admin user when simple authentication is in effect. * * @throws Exception if anything goes wrong */ @@ -316,6 +315,26 @@ env.put( Context.PROVIDER_URL, "ou=system" ); env.put( Context.SECURITY_PRINCIPAL, "uid=admin,ou=system" ); env.put( Context.SECURITY_CREDENTIALS, "testing" ); + env.put( Context.SECURITY_AUTHENTICATION, "simple" ); + env.put( Context.INITIAL_CONTEXT_FACTORY, "org.apache.eve.jndi.EveContextFactory" ); + 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 + { + // now go in as anonymous user and we should be rejected + 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.eve.jndi.EveContextFactory" ); assertNotNull( new InitialContext( env ) ); }
