Changeset 10535
- Timestamp:
- 26 Aug 2013, 13:04:51 (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
r10526 r10535 173 173 return (False, 'Invalid username or password.') 174 174 175 175 176 class KofaMoodleAuthenticator(KofaAuthenticator): 176 177 """Authenticate against a running Kofa instance and transfer … … 179 180 Configuration of Moodle: 180 181 1. Set 'passwordpolicy' to No 181 2. Create external web service 'Kofa' with the following functions: 182 core_user_create_users, core_user_get_users, 183 core_user_update_users, enrol_manual_enrol_users 184 3. Create token for the admin user (no special web service user needed) 185 and for service 'Kofa' 186 4. Enable and configure CAS server authentication. 187 CAS protocol version is 1.0. Moodle expects SSL/TLS protocol. 188 """ 189 182 183 2. Create external web service 'Kofa' with the following 184 functions: core_user_create_users, core_user_get_users, 185 core_user_update_users, enrol_manual_enrol_users 186 187 3. Create token for the admin user (no special web service user 188 needed) and for service 'Kofa' 189 190 4. Enable and configure CAS server authentication. CAS protocol 191 version is 1.0. Moodle expects SSL/TLS protocol. 192 """ 190 193 name = 'kofa_moodle1' 191 194 … … 226 229 try: 227 230 result = moodle.core_user_update_users([ 228 {'id': user_id,'auth':'cas'}])231 {'id': user_id, 'auth': 'cas'}]) 229 232 except xmlrpclib.Fault: 230 233 faultstring = sys.exc_info()[1].faultString … … 247 250 moodle = xmlrpclib.ServerProxy( 248 251 backend['moodle_url'], allow_none=True) 249 principal = proxy.check_applicant_credentials(kofa_username, password) 252 principal = proxy.check_applicant_credentials( 253 kofa_username, password) 250 254 if principal is None: 251 principal = proxy.check_student_credentials(kofa_username, password) 255 principal = proxy.check_student_credentials( 256 kofa_username, password) 252 257 if principal is None: 253 258 return (False, 'Invalid username or password') … … 260 265 return (False, 'User not eligible') 261 266 return (False, 'Invalid username or password') 262 -
main/waeup.cas/trunk/waeup/cas/tests/test_authenticators.py
r10526 r10535 1 3# Tests for waeup.cas.authentictors1 # Tests for waeup.cas.authentictors 2 2 import os 3 3 import threading … … 88 88 url='http://localhost:6666/', 89 89 marker='^SCHOOL1-', 90 moodle_url ='http://localhost:7777/',90 moodle_url='http://localhost:7777/', 91 91 ) 92 92 ) 93 93 94 94 95 class KofaAuthenticatorTests(unittest.TestCase): … … 132 133 assert app.db_connection_string == 'sqlite:///:memory:' 133 134 assert isinstance(app.auth, KofaAuthenticator) 135 134 136 135 137 class KofaMoodleAuthenticatorTests(unittest.TestCase): … … 148 150 {'url': 'http://xmlrpcuser1:xmlrpcuser1@localhost:8080/app1/', 149 151 'marker': '^K', 150 'moodle_url': 'http://localhost/moodle/webservice/xmlrpc/server.php?wstoken=de1e1cbacf91ec6290bb6f6339122e7d', 152 'moodle_url': ('http://localhost/moodle/webservice/xmlrpc' 153 '/server.php?wstoken=de1e1cbacf91ec6290bb6' 154 'f6339122e7d'), 151 155 }, 152 156 } … … 214 218 ) 215 219 220 216 221 class FakeMoodleServer(SimpleXMLRPCServer): 217 222 # A fake Moodle server that provides only XMLRPC methods … … 242 247 raise xmlrpclib.Fault('faultCode', 'core_user_get_users failed') 243 248 if arg[0]['value'] == 'SCHOOL1-fault3': 244 return {'users': [{'id':'SCHOOL1-fault3'}]}249 return {'users': [{'id': 'SCHOOL1-fault3'}]} 245 250 if arg[0]['value'] in ('SCHOOL1-fault4', 'SCHOOL1-fault5'): 246 return {'users': [{'id': 123}]}251 return {'users': [{'id': 123}]} 247 252 return {'users': []} 248 253 … … 252 257 raise xmlrpclib.Fault('faultCode', 'core_user_update_users failed') 253 258 return None 259 254 260 255 261 class KofaAuthenticatorsIntegrationTests(unittest.TestCase): … … 271 277 # set up a fake moodle server 272 278 cls.moodle_server = FakeMoodleServer(('localhost', 7777)) 273 cls.moodle_th = threading.Thread(target=cls.moodle_server.serve_forever) 279 cls.moodle_th = threading.Thread( 280 target=cls.moodle_server.serve_forever) 274 281 cls.moodle_th.daemon = True 275 282 cls.moodle_th.start() … … 319 326 result = proxy.core_user_create_users( 320 327 [{'username': 'any name'}]) 321 assert result == 328 assert result == [{'id': 37, 'username': 'any name'}] 322 329 self.assertRaises( 323 330 xmlrpclib.Fault, proxy.core_user_create_users, … … 354 361 result1s = auth.check_credentials('SCHOOL1-bird', 'bebop') 355 362 assert result1s == (True, '') 356 result1a 363 result1a = auth.check_credentials('SCHOOL1-pig', 'pog') 357 364 assert result1a == (True, '') 358 365 # user does not exist
Note: See TracChangeset for help on using the changeset viewer.