Changeset 10475
- Timestamp:
- 8 Aug 2013, 10:09:00 (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
r10474 r10475 1 1 """Components that do the real authentication stuff. 2 2 """ 3 import re 3 4 from pkg_resources import iter_entry_points 4 5 … … 117 118 name = 'kofa1' 118 119 119 def __init__(self, auth_backends=None): 120 self.backends = auth_backends 120 def __init__(self, auth_backends="{}"): 121 try: 122 self.backends = eval(auth_backends) 123 except: 124 raise ValueError('auth_backends must be a ' 125 'valid Python expression.') 126 self._check_options() 127 128 def _check_options(self): 129 if not isinstance(self.backends, dict): 130 raise ValueError('Backends must be configured as dicts.') 131 for key, val in self.backends.items(): 132 if not isinstance(val, dict): 133 raise ValueError( 134 'Backend %s: config must be a dict' % key) 135 if not 'url' in val: 136 raise ValueError( 137 'Backend %s: config must contain an `url` key.' % key) 138 if not 'marker' in val: 139 self.backends[key]['marker'] = '.+' 140 try: 141 re.compile(self.backends[key]['marker']) 142 except: 143 raise ValueError( 144 'Backend %s: marker must be a valid regular expr.:' % ( 145 key,)) 121 146 122 147 def check_credentials(self, username='', password=''): -
main/waeup.cas/trunk/waeup/cas/tests/test_authenticators.py
r10474 r10475 62 62 inst1 = dict( 63 63 url = 'http://localhost:6666/app', 64 marker = '^M[0-9]+ ',64 marker = '^M[0-9]+$', 65 65 ) 66 66 ) … … 76 76 # all options have sensible defaults 77 77 auth = KofaAuthenticator() 78 assert auth.backends is None78 assert auth.backends == {} 79 79 80 80 def test_options(self): 81 81 # we can pass options 82 auth = KofaAuthenticator(auth_backends= BACKENDS)82 auth = KofaAuthenticator(auth_backends=str(BACKENDS)) 83 83 assert auth.backends == BACKENDS 84 auth = KofaAuthenticator(auth_backends='{"foo": {"url": "bar"}}') 85 assert auth.backends['foo']['marker'] == '.+' 86 self.assertRaises( 87 ValueError, KofaAuthenticator, auth_backends='not-a-py-expr') 88 self.assertRaises( 89 ValueError, KofaAuthenticator, auth_backends='"Not a dict"') 90 self.assertRaises( 91 ValueError, KofaAuthenticator, 92 auth_backends='{"foo": "not-a-dict"}') 93 self.assertRaises( 94 ValueError, KofaAuthenticator, 95 auth_backends='{"foo": {"no-url-key": "bar"}}') 96 self.assertRaises( 97 ValueError, KofaAuthenticator, 98 auth_backends='{"foo": {"url": "bar", "marker": "inv_re)"}}') 84 99 85 100 def test_paste_deploy_options(self):
Note: See TracChangeset for help on using the changeset viewer.