[Zope-CVS] CVS: Products/PluggableAuthService/plugins/tests - helpers.py:1.1.2.1 test_HTTPBasicAuthHelper.py:1.3.4.1 test_ZODBGroupManager.py:1.3.4.1 test_ZODBRoleManager.py:1.3.4.1 test_ZODBUserManager.py:1.3.4.1

Lennart Regebro regebro at nuxeo.com
Tue Aug 31 10:42:14 EDT 2004


Update of /cvs-repository/Products/PluggableAuthService/plugins/tests
In directory cvs.zope.org:/tmp/cvs-serv26731/plugins/tests

Modified Files:
      Tag: regebro-implement_challenge-branch
	test_HTTPBasicAuthHelper.py test_ZODBGroupManager.py 
	test_ZODBRoleManager.py test_ZODBUserManager.py 
Added Files:
      Tag: regebro-implement_challenge-branch
	helpers.py 
Log Message:
Merge from HEAD + new challenge implementation.


=== Added File Products/PluggableAuthService/plugins/tests/helpers.py ===
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights
# Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL).  A copy of the ZPL should accompany this
# distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
from Products.PluggableAuthService.tests.test_PluggableAuthService \
    import FauxContainer

class FauxPAS( FauxContainer ):

    def __init__( self ):
        self._id = 'acl_users'

    def searchPrincipals( self, **kw ):
        id = kw.get( 'id' )
        return [ { 'id': id } ]

class FauxSmartPAS( FauxContainer ):

    def __init__( self ):
        self._id = 'acl_users'
        self.user_ids = {}

    def searchPrincipals( self, **kw ):
        id = kw.get( 'id' )
        prin = self.user_ids.get(id, None)
        return (prin and [ { 'id': id } ]) or []

class DummyUser:

    def __init__( self, id ):
        self._id = id

    def getId( self ):
        return self._id



=== Products/PluggableAuthService/plugins/tests/test_HTTPBasicAuthHelper.py 1.3 => 1.3.4.1 ===
--- Products/PluggableAuthService/plugins/tests/test_HTTPBasicAuthHelper.py:1.3	Thu Aug 12 11:15:55 2004
+++ Products/PluggableAuthService/plugins/tests/test_HTTPBasicAuthHelper.py	Tue Aug 31 10:41:43 2004
@@ -13,10 +13,14 @@
 #
 ##############################################################################
 import unittest
-from conformance import ILoginPasswordHostExtractionPlugin_conformance
-from conformance import IChallengePlugin_conformance
-from conformance import ICredentialsUpdatePlugin_conformance
-from conformance import ICredentialsResetPlugin_conformance
+from Products.PluggableAuthService.tests.conformance \
+     import ILoginPasswordHostExtractionPlugin_conformance
+from Products.PluggableAuthService.tests.conformance \
+     import IChallengePlugin_conformance
+from Products.PluggableAuthService.tests.conformance \
+     import ICredentialsUpdatePlugin_conformance
+from Products.PluggableAuthService.tests.conformance \
+     import ICredentialsResetPlugin_conformance
 
 class FauxHTTPRequest:
 


=== Products/PluggableAuthService/plugins/tests/test_ZODBGroupManager.py 1.3 => 1.3.4.1 ===
--- Products/PluggableAuthService/plugins/tests/test_ZODBGroupManager.py:1.3	Thu Aug 12 11:15:55 2004
+++ Products/PluggableAuthService/plugins/tests/test_ZODBGroupManager.py	Tue Aug 31 10:41:43 2004
@@ -19,17 +19,8 @@
 from Products.PluggableAuthService.tests.conformance \
     import IGroupsPlugin_conformance
 
-from Products.PluggableAuthService.tests.test_PluggableAuthService \
-    import FauxContainer
-
-class FauxPAS( FauxContainer ):
-
-    def __init__( self ):
-        self._id = 'acl_users'
-        
-    def searchPrincipals( self, **kw ):
-        id = kw.get( 'id' )
-        return [ { 'id': id } ]
+from Products.PluggableAuthService.plugins.tests.helpers \
+     import FauxPAS, FauxSmartPAS, DummyUser
 
 class DummyGroup:
 
@@ -39,14 +30,6 @@
     def getId( self ):
         return self._id
 
-class DummyUser:
-
-    def __init__( self, id ):
-        self._id = id
-
-    def getId( self ):
-        return self._id
-
 class ZODBGroupManagerTests( unittest.TestCase
                            , IGroupEnumerationPlugin_conformance
                            , IGroupsPlugin_conformance
@@ -119,10 +102,36 @@
         zgm.addGroup( 'group' )
 
         user = DummyUser( 'userid' )
-        
+
         zgm.addPrincipalToGroup( user.getId(), 'group' )
         groups = zgm.getGroupsForPrincipal( user )
         self.assertEqual( groups, ( 'group', ) )
+
+    def test_addPrincipalToGroupThenRemovePrincipal( self ):
+
+        root = FauxSmartPAS()
+        root.user_ids['foo'] = 'foo'
+
+        zgm = self._makeOne( id='groups' ).__of__( root )
+
+        zgm.addGroup( 'group', 'group_title', 'group_desc' )
+        self.assertEqual( len( zgm.listAssignedPrincipals( 'group' ) ), 0 )
+
+        new = zgm.addPrincipalToGroup( 'foo', 'group' )
+
+        self.failUnless( new )
+
+        assigned = [x[1] for x in zgm.listAssignedPrincipals( 'group' )]
+
+        self.assertEqual( len( assigned ), 1 )
+        self.assertEqual( assigned[0], 'foo' )
+
+        del root.user_ids['foo']
+
+        assigned = [x[1] for x in zgm.listAssignedPrincipals( 'group' )]
+
+        self.assertEqual( len( assigned ), 1 )
+        self.assertEqual( assigned[0], '<foo: not found>' )
 
     def test_removePrincipalFromGroup( self ):
 


=== Products/PluggableAuthService/plugins/tests/test_ZODBRoleManager.py 1.3 => 1.3.4.1 ===
--- Products/PluggableAuthService/plugins/tests/test_ZODBRoleManager.py:1.3	Thu Aug 12 11:15:55 2004
+++ Products/PluggableAuthService/plugins/tests/test_ZODBRoleManager.py	Tue Aug 31 10:41:43 2004
@@ -21,25 +21,8 @@
 from Products.PluggableAuthService.tests.conformance \
     import IRoleAssignerPlugin_conformance
 
-from Products.PluggableAuthService.tests.test_PluggableAuthService \
-    import FauxContainer
-
-class FauxPAS( FauxContainer ):
-
-    def __init__( self ):
-        self._id = 'acl_users'
-        
-    def searchPrincipals( self, **kw ):
-        id = kw.get( 'id' )
-        return [ { 'id': id } ]
-
-class DummyUser:
-
-    def __init__( self, id ):
-        self._id = id
-
-    def getId( self ):
-        return self._id
+from Products.PluggableAuthService.plugins.tests.helpers \
+     import FauxPAS, FauxSmartPAS, DummyUser
 
 class ZODBRoleManagerTests( unittest.TestCase
                           , IRolesPlugin_conformance
@@ -264,7 +247,7 @@
                          , () )
 
     def test_assignRoleToPrincipal_nonesuch( self ):
-        
+
         from Products.PluggableAuthService.tests.test_PluggableAuthService \
             import FauxRoot
 
@@ -274,7 +257,7 @@
         self.assertRaises( KeyError, zrm.assignRoleToPrincipal, 'test', 'foo' )
 
     def test_assignRoleToPrincipal_user( self ):
-        
+
         from Products.PluggableAuthService.tests.test_PluggableAuthService \
             import FauxRoot
 
@@ -301,7 +284,7 @@
         self.failUnless( 'test2' in roles )
 
     def test_assignRoleToPrincipal_new( self ):
-        
+
         root = FauxPAS()
         zrm = self._makeOne( id='assign_new' ).__of__( root )
 
@@ -318,7 +301,7 @@
         self.assertEqual( assigned[0], 'foo' )
 
     def test_assignRoleToPrincipal_already( self ):
-        
+
         root = FauxPAS()
         zrm = self._makeOne( id='assign_already' ).__of__( root )
 
@@ -334,8 +317,34 @@
         self.assertEqual( len( assigned ), 1 )
         self.assertEqual( assigned[0], 'foo' )
 
+    def test_assignRoleBeforeRemovingPrincipal( self ):
+
+        root = FauxSmartPAS()
+        root.user_ids['foo'] = 'foo'
+
+        zrm = self._makeOne( id='assign_before_remove' ).__of__( root )
+
+        zrm.addRole( 'test' )
+        self.assertEqual( len( zrm.listAssignedPrincipals( 'test' ) ), 0 )
+
+        new = zrm.assignRoleToPrincipal( 'test', 'foo' )
+
+        self.failUnless( new )
+
+        assigned = [x[1] for x in zrm.listAssignedPrincipals( 'test' )]
+
+        self.assertEqual( len( assigned ), 1 )
+        self.assertEqual( assigned[0], 'foo' )
+
+        del root.user_ids['foo']
+
+        assigned = [x[1] for x in zrm.listAssignedPrincipals( 'test' )]
+
+        self.assertEqual( len( assigned ), 1 )
+        self.assertEqual( assigned[0], '<foo: not found>' )
+
     def test_removeRoleFromPrincipal_nonesuch( self ):
-        
+
         from Products.PluggableAuthService.tests.test_PluggableAuthService \
             import FauxRoot
 
@@ -346,7 +355,7 @@
                          , 'test', 'foo' )
 
     def test_removeRoleFromPrincipal_existing( self ):
-        
+
         root = FauxPAS()
         zrm = self._makeOne( id='remove_existing' ).__of__( root )
 
@@ -373,7 +382,7 @@
         self.failUnless( 'baz' in assigned )
 
     def test_removeRoleFromPrincipal_noop( self ):
-        
+
         root = FauxPAS()
         zrm = self._makeOne( id='remove_noop' ).__of__( root )
 
@@ -390,7 +399,7 @@
         removed = zrm.removeRoleFromPrincipal( 'test', 'bar' )
 
         self.failIf( removed )
-        
+
     def test_updateRole_nonesuch( self ):
 
         from Products.PluggableAuthService.tests.test_PluggableAuthService \
@@ -425,7 +434,7 @@
         self.assertEqual( info[ 'description' ], 'Updated description' )
 
     def test_removeRole_then_addRole( self ):
-        
+
         from Products.PluggableAuthService.tests.test_PluggableAuthService \
             import FauxRoot
 


=== Products/PluggableAuthService/plugins/tests/test_ZODBUserManager.py 1.3 => 1.3.4.1 ===
--- Products/PluggableAuthService/plugins/tests/test_ZODBUserManager.py:1.3	Thu Aug 12 11:15:55 2004
+++ Products/PluggableAuthService/plugins/tests/test_ZODBUserManager.py	Tue Aug 31 10:41:43 2004
@@ -324,5 +324,39 @@
             self.failUnless( info[ 'id' ] in SUBSET_IDS )
             self.failUnless( info[ 'login' ] in SUBSET_LOGINS )
 
+    def test_authenticateWithOldPasswords( self ):
+
+        import sha
+
+        zum = self._makeOne()
+
+        # synthesize an older account
+
+        old_password = sha.sha( 'old_password' ).hexdigest()
+        zum._user_passwords[ 'old_user' ] = old_password
+        zum._login_to_userid[ 'old_user at example.com' ] = 'old_user'
+        zum._userid_to_login[ 'old_user' ] = 'old_user at example.com'
+
+        # create a new user
+
+        zum.addUser( 'new_user', 'new_user at example.com', 'new_password' )
+
+        user_id, login = zum.authenticateCredentials(
+                                { 'login' : 'old_user at example.com'
+                                , 'password' : 'old_password'
+                                } )
+
+        self.assertEqual( user_id, 'old_user' )
+        self.assertEqual( login, 'old_user at example.com' )
+
+        user_id, login = zum.authenticateCredentials(
+                                { 'login' : 'new_user at example.com'
+                                , 'password' : 'new_password'
+                                } )
+
+        self.assertEqual( user_id, 'new_user' )
+        self.assertEqual( login, 'new_user at example.com' )
+
+
 if __name__ == "__main__":
     unittest.main()



More information about the Zope-CVS mailing list