- Timestamp:
- 17 May 2011, 23:41:15 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/trunk/src/waeup/sirp/applicants/tests/test_authentication.py
r6112 r6123 38 38 from waeup.sirp.testing import FunctionalLayer 39 39 from waeup.sirp.app import University 40 from waeup.sirp.applicants import ApplicantsContainer, Applicant 40 41 from waeup.sirp.applicants.authentication import ( 41 42 ApplicantsAuthenticatorPlugin, WAeUPApplicantCredentialsPlugin, 42 43 ApplicantCredentials, AuthenticatedApplicantPrincipalFactory, 43 ApplicantPrincipalInfo, ApplicantPrincipal )44 ApplicantPrincipalInfo, ApplicantPrincipal,) 44 45 45 46 … … 66 67 self['applicants'] = { 67 68 'APP': { 68 'APP-12345': FakeApplication( 'APP-12345'),69 'APP-54321': FakeApplication( 'APP-54321'),70 'APP-22222': FakeApplication( 'APP-OTHER'),69 'APP-12345': FakeApplication(u'APP-12345'), 70 'APP-54321': FakeApplication(u'APP-54321'), 71 'APP-22222': FakeApplication(u'APP-OTHER'), 71 72 'APP-44444': FakeApplication(), 72 'APP-55555': FakeApplication( 'APP-OTHER'),73 'APP-55555': FakeApplication(u'APP-OTHER'), 73 74 }, 74 75 'JAMB': { 75 76 'JAMB1': FakeApplication(), 76 'JAMB2': FakeApplication( 'APP-12345'),77 'JAMB3': FakeApplication( 'APP-54321'),78 'JAMB4': FakeApplication( 'APP-44444'),77 'JAMB2': FakeApplication(u'APP-12345'), 78 'JAMB3': FakeApplication(u'APP-54321'), 79 'JAMB4': FakeApplication(u'APP-44444'), 79 80 }, 80 81 } … … 93 94 } 94 95 95 class AuthenticatorPluginTest(unittest.TestCase): 96 def FakeSite(): 97 return { 98 'applicants': { 99 'APP': { 100 'APP-12345': FakeApplication(u'APP-12345'), 101 'APP-54321': FakeApplication(u'APP-54321'), 102 'APP-22222': FakeApplication(u'APP-OTHER'), 103 'APP-44444': FakeApplication(), 104 'APP-55555': FakeApplication(u'APP-OTHER'), 105 }, 106 'JAMB': { 107 'JAMB1': FakeApplication(), 108 'JAMB2': FakeApplication(u'APP-12345'), 109 'JAMB3': FakeApplication(u'APP-54321'), 110 'JAMB4': FakeApplication(u'APP-44444'), 111 }, 112 }, 113 'accesscodes': { 114 'APP': FakeBatch({ 115 'APP-12345': FakeAccessCode('APP-12345'), 116 'APP-54321': FakeAccessCode('APP-54321', True), 117 'APP-11111': FakeAccessCode('APP-11111'), 118 'APP-22222': FakeAccessCode('APP-22222'), 119 'APP-33333': FakeAccessCode('APP-33333', True), 120 'APP-44444': FakeAccessCode('APP-44444', True), 121 'APP-55555': FakeAccessCode('APP-55555', True), 122 'APP-66666': FakeAccessCode('APP-66666', True, False), 123 'APP-77777': FakeAccessCode('APP-77777', False, False), 124 }) 125 } 126 } 127 128 class AuthenticatorPluginTest(FunctionalTestCase): 129 130 layer = FunctionalLayer 131 132 def create_applicant(self, cname, aname, ac=None): 133 # Create an applicant in an applicants container 134 setSite(self.app) 135 if not cname in self.app['applicants'].keys(): 136 container = ApplicantsContainer() 137 self.app['applicants'][cname] = container 138 applicant = Applicant() 139 if ac is not None: 140 applicant.access_code = ac 141 self.app['applicants'][cname][aname] = applicant 142 return 96 143 97 144 def setUp(self): 98 self.app = FakeSite() 99 self.app.setSiteManager(LocalSiteManager(self.app)) 145 super(AuthenticatorPluginTest, self).setUp() 146 147 # Setup a sample site for each test 148 app = University() 149 self.dc_root = tempfile.mkdtemp() 150 app['datacenter'].setStoragePath(self.dc_root) 151 152 # Prepopulate the ZODB... 153 self.getRootFolder()['app'] = app 154 self.app = self.getRootFolder()['app'] 155 156 fake_site = FakeSite() 157 for ckey, fake_container in fake_site['applicants'].items(): 158 for akey, fake_appl in fake_container.items(): 159 self.create_applicant(ckey, akey, fake_appl.access_code) 160 del self.app['accesscodes'] 161 self.app['accesscodes'] = fake_site['accesscodes'] 162 100 163 self.plugin = ApplicantsAuthenticatorPlugin() 101 setSite(self.app)102 164 return 103 165 104 166 def tearDown(self): 105 clearSite() 167 super(AuthenticatorPluginTest, self).tearDown() 168 shutil.rmtree(self.dc_root) 106 169 return 107 170 … … 120 183 # Possible cases, where formal correct authentication 121 184 # data is not valid: 185 # XXX: fails 122 186 result = self.plugin.authenticateCredentials( 123 187 dict(accesscode='APP-22222')) … … 131 195 dict(accesscode='APP-44444')) 132 196 assert result is None 133 197 134 198 result = self.plugin.authenticateCredentials( 135 199 dict(accesscode='APP-55555')) … … 177 241 def get(self, key, default=None): 178 242 return self.__getitem__(key, default) 179 243 180 244 def __getitem__(self, key, default=None): 181 245 return session_data.get(key, default) … … 317 381 # credentials plugin) to be registered with the local PAU. Admins 318 382 # can remove these components on the fly later-on if they wish. 319 383 320 384 layer = FunctionalLayer 321 385 322 386 def setUp(self): 323 387 super(PAUSetupTest, self).setUp() … … 348 412 cred_names = [name for name, plugin in cred_plugins] 349 413 auth_names = [name for name, plugin in auth_plugins] 350 414 351 415 # Make sure our local ApplicantsAuthenticatorPlugin is registered... 352 416 self.assertTrue('applicants' in auth_names)
Note: See TracChangeset for help on using the changeset viewer.