Changeset 10523
- Timestamp:
- 22 Aug 2013, 06:52:16 (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
r10522 r10523 159 159 """ 160 160 for backend_name, backend in self.backends.items(): 161 if not re.match(backend['marker'], username): 162 continue 163 # remove school marker 164 username = RE_SCHOOL_MARKER.sub('', username) 161 if backend['marker']: 162 if not re.match(backend['marker'], username): 163 continue 164 # remove school marker 165 username = RE_SCHOOL_MARKER.sub('', username) 165 166 proxy = xmlrpclib.ServerProxy( 166 167 backend['url'], allow_none=True) … … 204 205 except xmlrpclib.Fault: 205 206 faultstring = sys.exc_info()[1].faultString 207 if 'Email address already exists' in faultstring: 208 return (False, 209 'Another Moodle user is using the same email address.' 210 ' Email addresses can\'t be used twice in Moodle.') 206 211 if not 'Username already exists' in faultstring: 207 212 return (False, faultstring) … … 229 234 """ 230 235 for backend_name, backend in self.backends.items(): 231 if not re.match(backend['marker'], username): 232 continue 233 # remove school marker 234 username = RE_SCHOOL_MARKER.sub('', username) 236 if backend['marker']: 237 if not re.match(backend['marker'], username): 238 continue 239 # remove school marker 240 kofa_username = RE_SCHOOL_MARKER.sub('', username) 241 else: 242 kofa_username = username 235 243 proxy = xmlrpclib.ServerProxy( 236 244 backend['url'], allow_none=True) 237 245 moodle = xmlrpclib.ServerProxy( 238 246 backend['moodle_url'], allow_none=True) 239 principal = proxy.check_applicant_credentials( username, password)247 principal = proxy.check_applicant_credentials(kofa_username, password) 240 248 if principal is None: 241 principal = proxy.check_student_credentials( username, password)249 principal = proxy.check_student_credentials(kofa_username, password) 242 250 if principal is None: 243 251 return (False, 'Invalid username or password') 244 252 if principal['type'] == 'student': 245 userdata = proxy.get_student_moodle_data( username)253 userdata = proxy.get_student_moodle_data(kofa_username) 246 254 return self._create_user(username, userdata, moodle) 247 255 if principal['type'] == 'applicant': 248 userdata = proxy.get_applicant_moodle_data( username)256 userdata = proxy.get_applicant_moodle_data(kofa_username) 249 257 return self._create_user(username, userdata, moodle) 250 258 return (False, 'User not eligible') -
main/waeup.cas/trunk/waeup/cas/tests/test_authenticators.py
r10522 r10523 1 # Tests for waeup.cas.authentictors1 3# Tests for waeup.cas.authentictors 2 2 import os 3 3 import threading … … 229 229 def _core_user_create_users(self, arg): 230 230 # fake Moodle core_user_create_users method. 231 if arg[0]['username'] == ' fault1':231 if arg[0]['username'] == 'school1-fault1': 232 232 raise xmlrpclib.Fault('faultCode', 'faultString') 233 if arg[0]['username'] in (' fault4', 'fault5'):233 if arg[0]['username'] in ('school1-fault4', 'school1-fault5'): 234 234 raise xmlrpclib.Fault('faultCode', 'Username already exists') 235 235 return None … … 237 237 def _core_user_get_users(self, arg): 238 238 # fake Moodle core_user_get_users method. 239 if arg[0]['value'] == ' fault2':239 if arg[0]['value'] == 'SCHOOL1-fault2': 240 240 raise xmlrpclib.Fault('faultCode', 'faultString') 241 if arg[0]['value'] == ' fault3':242 return {'users':[{'id':' fault3'}]}241 if arg[0]['value'] == 'SCHOOL1-fault3': 242 return {'users':[{'id':'SCHOOL1-fault3'}]} 243 243 return {'users':[{'id':'any id'}]} 244 244 245 245 def _core_user_update_users(self, arg): 246 246 # fake Moodle core_user_update_users method. 247 if arg[0]['id'] == ' fault3':247 if arg[0]['id'] == 'SCHOOL1-fault3': 248 248 raise xmlrpclib.Fault('faultCode', 'faultString') 249 249 return None … … 318 318 self.assertRaises( 319 319 xmlrpclib.Fault, proxy.core_user_create_users, 320 [{'username': ' fault1'}])320 [{'username': 'school1-fault1'}]) 321 321 # test core_user_get_users 322 322 result = proxy.core_user_get_users( … … 325 325 self.assertRaises( 326 326 xmlrpclib.Fault, proxy.core_user_get_users, 327 [{'key': 'username', 'value': ' fault2'}])327 [{'key': 'username', 'value': 'SCHOOL1-fault2'}]) 328 328 # test core_user_update_users 329 329 result = proxy.core_user_update_users( … … 332 332 self.assertRaises( 333 333 xmlrpclib.Fault, proxy.core_user_update_users, 334 [{'id': ' fault3'}])334 [{'id': 'SCHOOL1-fault3'}]) 335 335 return 336 336 … … 359 359 assert result8 == (False, 'User not eligible') 360 360 361 # exceptions are raised in the foll woing cases361 # exceptions are raised in the following cases 362 362 result4s = auth.check_credentials('SCHOOL1-fault1', 'biz') 363 363 assert result4s == (False, 'faultString')
Note: See TracChangeset for help on using the changeset viewer.