Changeset 10518 for main/waeup.cas/trunk/waeup/cas
- Timestamp:
- 21 Aug 2013, 11:44:28 (11 years ago)
- Location:
- main/waeup.cas/trunk/waeup/cas
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.cas/trunk/waeup/cas/authenticators.py
r10517 r10518 241 241 userdata = proxy.get_student_moodle_data(username) 242 242 return self._create_user(username, userdata, moodle) 243 return (False, 'Invalid username or password.') 243 if principal['type'] == 'applicant': 244 userdata = proxy.get_applicant_moodle_data(username) 245 return self._create_user(username, userdata, moodle) 246 return (False, 'Invalid username or password or user not eligible.') -
main/waeup.cas/trunk/waeup/cas/tests/test_authenticators.py
r10515 r10518 167 167 self._check_credentials, 'check_student_credentials') 168 168 self.register_function( 169 self._get_student_moodle_data, 'get_student_moodle_data') 169 self._get_moodle_data, 'get_student_moodle_data') 170 self.register_function( 171 self._get_moodle_data, 'get_applicant_moodle_data') 170 172 171 173 def _check_credentials(self, username, password): … … 186 188 'fault1', 'fault2', 'fault3', 'fault4') and password == 'biz': 187 189 return {'type': 'student'} 190 if username == 'fault5' and password == 'biz': 191 return {'type': 'applicant'} 188 192 return None 189 193 190 def _get_ student_moodle_data(self, username):194 def _get_moodle_data(self, username): 191 195 # fake waeup.kofa get_student_moodle_data method. 192 196 if username == 'bird': … … 200 204 lastname='Charles', 201 205 ) 202 if username in ('fault1', 'fault2', 'fault3', 'fault4' ):206 if username in ('fault1', 'fault2', 'fault3', 'fault4', 'fault5'): 203 207 return dict(email='ff@ff.ff', 204 208 firstname='John', … … 225 229 if arg[0]['username'] == 'fault1': 226 230 raise xmlrpclib.Fault('faultCode', 'faultString') 227 if arg[0]['username'] == 'fault4':231 if arg[0]['username'] in ('fault4', 'fault5'): 228 232 raise xmlrpclib.Fault('faultCode', 'Username already exists') 229 233 return None … … 295 299 'firstname': 'Ray', 296 300 } 301 result = proxy.get_applicant_moodle_data('pig') 302 assert result == { 303 'lastname': 'Charles', 304 'email': 'bb@bb.bb', 305 'firstname': 'Ray', 306 } 297 307 return 298 308 … … 323 333 return 324 334 325 def test_check_credentials_ 1(self):335 def test_check_credentials_KofaAuthenticator(self): 326 336 # we get real responses when querying Kofa instances 327 337 auth = KofaAuthenticator(auth_backends=str(BACKENDS2)) … … 333 343 assert result3 == (False, 'Invalid username or password.') 334 344 335 def test_check_credentials_ 2(self):345 def test_check_credentials_KofaMoodleAuthenticator(self): 336 346 # we get real responses when querying Kofa instances 337 347 auth = KofaMoodleAuthenticator(auth_backends=str(BACKENDS3)) 338 result1 = auth.check_credentials('SCHOOL1-bird', 'bebop') 339 assert result1 == (True, '') 340 result2 = auth.check_credentials('SCHOOL1-foo', 'bar') 341 assert result2 == (False, 'Invalid username or password.') 342 result3 = auth.check_credentials('SCHOOL2-bar', 'baz') 343 assert result3 == (False, 'Invalid username or password.') 348 result1s = auth.check_credentials('SCHOOL1-bird', 'bebop') 349 assert result1s == (True, '') 350 result1a = auth.check_credentials('SCHOOL1-pig', 'pog') 351 assert result1a == (True, '') 352 result2s = auth.check_credentials('SCHOOL1-foo', 'bar') 353 assert result2s == ( 354 False, 'Invalid username or password or user not eligible.') 355 result3s = auth.check_credentials('SCHOOL2-bar', 'baz') 356 assert result3s == ( 357 False, 'Invalid username or password or user not eligible.') 358 344 359 # exceptions are raised in the follwoing cases 345 result4 = auth.check_credentials('SCHOOL1-fault1', 'biz') 346 assert result4 == (False, 'faultString') 347 result5 = auth.check_credentials('SCHOOL1-fault2', 'biz') 348 assert result5 == (False, 'faultString') 349 result6 = auth.check_credentials('SCHOOL1-fault3', 'biz') 350 assert result6 == (False, 'faultString') 360 result4s = auth.check_credentials('SCHOOL1-fault1', 'biz') 361 assert result4s == (False, 'faultString') 362 result5s = auth.check_credentials('SCHOOL1-fault2', 'biz') 363 assert result5s == (False, 'faultString') 364 result6s = auth.check_credentials('SCHOOL1-fault3', 'biz') 365 assert result6s == (False, 'faultString') 366 351 367 # no exception if user exists 352 result7 = auth.check_credentials('SCHOOL1-fault4', 'biz') 353 assert result7 == (True, '') 368 result7s = auth.check_credentials('SCHOOL1-fault4', 'biz') 369 assert result7s == (True, '') 370 result7a = auth.check_credentials('SCHOOL1-fault5', 'biz') 371 assert result7a == (True, '')
Note: See TracChangeset for help on using the changeset viewer.