- Timestamp:
- 4 Sep 2011, 23:35:58 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/trunk/src/waeup/sirp/students/tests/test_authentication.py
r6668 r6680 21 21 ## 22 22 import unittest 23 from zope.authentication.interfaces import IAuthentication 23 24 from zope.component import provideUtility, queryUtility, getGlobalSiteManager 24 25 from zope.interface.verify import verifyClass, verifyObject … … 26 27 from zope.password.interfaces import IPasswordManager 27 28 from zope.pluggableauth import PluggableAuthentication 29 from zope.securitypolicy.role import Role 30 from zope.securitypolicy.interfaces import IRole, Allow 31 from waeup.sirp.authentication import get_principal_role_manager 28 32 from waeup.sirp.interfaces import IAuthPluginUtility, IUserAccount 29 33 from waeup.sirp.students.authentication import ( … … 62 66 password = None 63 67 68 69 class MinimalPAU(PluggableAuthentication): 70 def getPrincipal(self, id): 71 return 'faked principal' 72 64 73 class StudentAccountTests(unittest.TestCase): 65 74 … … 67 76 self.fake_stud = FakeStudent() 68 77 self.account = StudentAccount(self.fake_stud) 78 79 # We provide a minimal PAU 80 pau = MinimalPAU() 81 provideUtility(pau, IAuthentication) 82 83 # We register a role 84 test_role = Role('waeup.test.Role', 'Testing Role') 85 provideUtility(test_role, IRole, name='waeup.test.Role') 86 69 87 # We have to setup a password manager utility manually as we 70 88 # have no functional test. In functional tests this would … … 76 94 77 95 def tearDown(self): 78 # Clear up the SSHA utility 79 ssha_manager = queryUtility( 80 IPasswordManager, name='SSHA', default=None) 81 if ssha_manager is not None: 82 gsm = getGlobalSiteManager() 83 gsm.unregisterUtility(ssha_manager) 96 self.account.roles = [] # make sure roles are reset 97 gsm = getGlobalSiteManager() 98 to_clean = [] 99 # Clear up utilities registered in setUp 100 to_clean.append( 101 (IPasswordManager, queryUtility( 102 IPasswordManager, name='SSHA', default=None))) 103 to_clean.append( 104 (IAuthentication, queryUtility(IAuthentication, default=None))) 105 to_clean.append( 106 (IRole, queryUtility(IRole, name='test.Role', default=None))) 107 for iface, elem in to_clean: 108 if elem is not None: 109 gsm.unregisterUtility(elem, iface) 84 110 return 85 111 … … 95 121 # we do not store plaintext passwords 96 122 self.assertTrue(self.fake_stud.password != 'secret') 123 # passwords are stored as unicode 124 self.assertTrue(isinstance(self.fake_stud.password, unicode)) 97 125 return 98 126 … … 107 135 self.assertEqual(result3, True) 108 136 return 137 138 def test_role_set(self): 139 # make sure we can set roles for principals denoted by account 140 prm = get_principal_role_manager() 141 self.assertEqual(prm.getPrincipalsAndRoles(), []) 142 self.account.roles = ['waeup.test.Role'] 143 self.assertEqual( 144 prm.getPrincipalsAndRoles(), 145 [('waeup.test.Role', 'test_stud', Allow)]) 146 return 147 148 def test_role_get(self): 149 # make sure we can get roles set for an account 150 self.assertEqual(self.account.roles, []) 151 self.account.roles = ['waeup.test.Role',] # set a role 152 self.assertEqual(self.account.roles, ['waeup.test.Role']) 153 return
Note: See TracChangeset for help on using the changeset viewer.