You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by ka...@apache.org on 2011/04/17 11:03:09 UTC

svn commit: r1094120 - /directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/authn/ppolicy/PasswordPolicyTest.java

Author: kayyagari
Date: Sun Apr 17 09:03:09 2011
New Revision: 1094120

URL: http://svn.apache.org/viewvc?rev=1094120&view=rev
Log:
o added a test for password lockout feature
o fixed the ppolicy response control creation

Modified:
    directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/authn/ppolicy/PasswordPolicyTest.java

Modified: directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/authn/ppolicy/PasswordPolicyTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/authn/ppolicy/PasswordPolicyTest.java?rev=1094120&r1=1094119&r2=1094120&view=diff
==============================================================================
--- directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/authn/ppolicy/PasswordPolicyTest.java (original)
+++ directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/authn/ppolicy/PasswordPolicyTest.java Sun Apr 17 09:03:09 2011
@@ -25,7 +25,7 @@ import static org.apache.directory.serve
 import static org.apache.directory.shared.ldap.extras.controls.PasswordPolicyErrorEnum.INSUFFICIENT_PASSWORD_QUALITY;
 import static org.apache.directory.shared.ldap.extras.controls.PasswordPolicyErrorEnum.PASSWORD_TOO_SHORT;
 import static org.apache.directory.shared.ldap.extras.controls.PasswordPolicyErrorEnum.PASSWORD_TOO_YOUNG;
-import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.*;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
@@ -48,6 +48,7 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.extras.controls.PasswordPolicyImpl;
 import org.apache.directory.shared.ldap.extras.controls.ppolicy_impl.PasswordPolicyDecorator;
 import org.apache.directory.shared.ldap.model.constants.LdapSecurityConstants;
+import org.apache.directory.shared.ldap.model.constants.PasswordPolicySchemaConstants;
 import org.apache.directory.shared.ldap.model.constants.SchemaConstants;
 import org.apache.directory.shared.ldap.model.entry.Attribute;
 import org.apache.directory.shared.ldap.model.entry.DefaultEntry;
@@ -204,6 +205,48 @@ public class PasswordPolicyTest extends 
 
 
     @Test
+    public void testPwdLockout() throws Exception
+    {
+        policyConfig.setPwdMaxFailure( 2 );
+        policyConfig.setPwdLockout( true );
+        policyConfig.setPwdLockoutDuration( 0 );
+        policyConfig.setPwdGraceAuthNLimit( 2 );
+        policyConfig.setPwdFailureCountInterval( 1 );
+        
+        LdapConnection connection = getAdminNetworkConnection( getLdapServer() );
+        
+        Dn userDn = new Dn( "cn=user,ou=system" );
+        Entry userEntry = new DefaultEntry( 
+            userDn.toString(), 
+            "ObjectClass: top", 
+            "ObjectClass: person", 
+            "cn: user",
+            "sn: user_sn", 
+            "userPassword: 12345" );
+
+        AddRequest addRequest = new AddRequestImpl();
+        addRequest.setEntry( userEntry );
+        addRequest.addControl( PP_REQ_CTRL );
+
+        AddResponse addResp = connection.add( addRequest );
+        assertEquals( ResultCodeEnum.SUCCESS, addResp.getLdapResult().getResultCode() );
+        PasswordPolicy respCtrl = getPwdRespCtrl( addResp );
+        assertNull( respCtrl );
+
+        for( int i=0; i< 4; i++ )
+        {
+            LdapConnection userConnection = getNetworkConnectionAs( getLdapServer(), userDn.getName(), "1234" );// wrong password
+            assertNotNull( userConnection );
+            assertFalse( userConnection.isAuthenticated() );
+        }
+        
+        userEntry = connection.lookup( userDn, "+" );
+        Attribute pwdAccountLockedTime = userEntry.get( PasswordPolicySchemaConstants.PWD_ACCOUNT_LOCKED_TIME_AT );
+        assertNotNull( pwdAccountLockedTime );
+    }
+
+    
+    @Test
     public void testPwdMinAge() throws Exception
     {
         policyConfig.setPwdMinAge( 5 );
@@ -253,13 +296,15 @@ public class PasswordPolicyTest extends 
 
     private PasswordPolicy getPwdRespCtrl( Response resp ) throws Exception
     {
-        CodecControl<? extends Control> ctrl = codec.newControl( resp.getControls().get( PP_REQ_CTRL.getOid() ) );
-
-        if ( ctrl == null )
+        Control control = resp.getControls().get( PP_REQ_CTRL.getOid() );
+        
+        if ( control == null )
         {
             return null;
         }
 
+        CodecControl<? extends Control> ctrl = codec.newControl( control );
+
         PasswordPolicyDecorator respCtrl = new PasswordPolicyDecorator( codec );
         respCtrl.setValue( ctrl.getValue() );
         return respCtrl;