You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2007/04/19 16:32:18 UTC
svn commit: r530428 -
/directory/apacheds/trunk/core-unit/src/test/java/org/apache/directory/server/core/authn/SimpleAuthenticationITest.java
Author: elecharny
Date: Thu Apr 19 07:32:16 2007
New Revision: 530428
URL: http://svn.apache.org/viewvc?view=rev&rev=530428
Log:
Added a test for SMD5 and SSHA. All the encryptions are now supported (Plain text, MD5, SMD5, SHA, SSHA, crypt)
Modified:
directory/apacheds/trunk/core-unit/src/test/java/org/apache/directory/server/core/authn/SimpleAuthenticationITest.java
Modified: directory/apacheds/trunk/core-unit/src/test/java/org/apache/directory/server/core/authn/SimpleAuthenticationITest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-unit/src/test/java/org/apache/directory/server/core/authn/SimpleAuthenticationITest.java?view=diff&rev=530428&r1=530427&r2=530428
==============================================================================
--- directory/apacheds/trunk/core-unit/src/test/java/org/apache/directory/server/core/authn/SimpleAuthenticationITest.java (original)
+++ directory/apacheds/trunk/core-unit/src/test/java/org/apache/directory/server/core/authn/SimpleAuthenticationITest.java Thu Apr 19 07:32:16 2007
@@ -442,7 +442,6 @@
assertTrue( attrs.get( "uid" ).contains( "akarasulu" ) );
}
- /**
public void testSSHA() throws NamingException
{
Hashtable<String,Object> env = new Hashtable<String,Object>( configuration.toJndiEnvironment() );
@@ -459,7 +458,7 @@
assertTrue( attrs.get( "uid" ).contains( "akarasulu" ) );
// now modify the password for akarasulu : 'secret', encrypted using SHA
- AttributeImpl userPasswordAttribute = new AttributeImpl( "userPassword", "{SSHA}Ksr5noqyunWvBi8FpkU8dygcTtjm9AOSii6Plg==" );
+ AttributeImpl userPasswordAttribute = new AttributeImpl( "userPassword", "{SSHA}mjVVxasFkk59wMW4L1Ldt+YCblfhULHs03WW7g==" );
ic.modifyAttributes( "uid=akarasulu,ou=users", new ModificationItemImpl[] {
new ModificationItemImpl( DirContext.REPLACE_ATTRIBUTE, userPasswordAttribute ) } );
@@ -494,7 +493,6 @@
assertNotNull( attrs );
assertTrue( attrs.get( "uid" ).contains( "akarasulu" ) );
}
- */
public void testMD5() throws NamingException
{
@@ -513,6 +511,58 @@
// now modify the password for akarasulu : 'secret', encrypted using MD5
AttributeImpl userPasswordAttribute = new AttributeImpl( "userPassword", "{MD5}Xr4ilOzQ4PCOq3aQ0qbuaQ==" );
+ ic.modifyAttributes( "uid=akarasulu,ou=users", new ModificationItemImpl[] {
+ new ModificationItemImpl( DirContext.REPLACE_ATTRIBUTE, userPasswordAttribute ) } );
+
+ // close and try with old password (should fail)
+ ic.close();
+ env.put( Context.SECURITY_CREDENTIALS, "test" );
+
+ try
+ {
+ ic = new InitialDirContext( env );
+ fail( "Authentication with old password should fail" );
+ }
+ catch ( NamingException e )
+ {
+ // we should fail
+ }
+
+ // close and try again now with new password (should be successfull)
+ ic.close();
+ env.put( Context.SECURITY_CREDENTIALS, "secret" );
+ ic = new InitialDirContext( env );
+ attrs = ic.getAttributes( "uid=akarasulu,ou=users" );
+ assertNotNull( attrs );
+ assertTrue( attrs.get( "uid" ).contains( "akarasulu" ) );
+
+ // close and try again now with new password, to check that the
+ // cache is updated (should be successfull)
+ ic.close();
+ env.put( Context.SECURITY_CREDENTIALS, "secret" );
+ ic = new InitialDirContext( env );
+ attrs = ic.getAttributes( "uid=akarasulu,ou=users" );
+ assertNotNull( attrs );
+ assertTrue( attrs.get( "uid" ).contains( "akarasulu" ) );
+ }
+
+ public void testSMD5() throws NamingException
+ {
+ Hashtable<String,Object> env = new Hashtable<String,Object>( configuration.toJndiEnvironment() );
+ 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.directory.server.core.jndi.CoreContextFactory" );
+ InitialDirContext ic = new InitialDirContext( env );
+
+ // Check that we can get the attributes
+ Attributes attrs = ic.getAttributes( "uid=akarasulu,ou=users" );
+ assertNotNull( attrs );
+ assertTrue( attrs.get( "uid" ).contains( "akarasulu" ) );
+
+ // now modify the password for akarasulu : 'secret', encrypted using SHA
+ AttributeImpl userPasswordAttribute = new AttributeImpl( "userPassword", "{SMD5}tQ9wo/VBuKsqBtylMMCcORbnYOJFMyDJ" );
ic.modifyAttributes( "uid=akarasulu,ou=users", new ModificationItemImpl[] {
new ModificationItemImpl( DirContext.REPLACE_ATTRIBUTE, userPasswordAttribute ) } );