source: main/waeup.cas/trunk/waeup/cas/tests/test_authenticators.py @ 10396

Last change on this file since 10396 was 10396, checked in by uli, 11 years ago

Let authtenticators give back a reason if login fails.

File size: 1.7 KB
Line 
1import unittest
2from waeup.cas.authenticators import (
3    get_all_authenticators, get_authenticator, filter_auth_opts,
4    Authenticator, DummyAuthenticator,
5    )
6
7
8class TestHelpers(unittest.TestCase):
9
10    def test_get_all_authenticators(self):
11        # we can get authenticators via entry points
12        auths = get_all_authenticators()
13        assert 'dummy' in auths
14        assert auths['dummy'] is DummyAuthenticator
15
16    def test_filter_auth_opts(self):
17        # we can filter auth opts
18        result = filter_auth_opts(
19            dict(auth='foo', auth_bar='baz', auth_baz='blah')
20            )
21        assert result == (
22            {'auth': 'foo'},
23            {'auth_bar': 'baz', 'auth_baz': 'blah'}
24            )
25
26    def test_get_authenticator(self):
27        # we can parse a paste.deploy config dict for auth
28        result = get_authenticator({})
29        assert result == {}
30        result = get_authenticator({'auth': 'dummy'})
31        assert isinstance(result['auth'], DummyAuthenticator)
32
33
34class AuthenticatorTests(unittest.TestCase):
35
36    def test_create(self):
37        # we can create Authenticator instances
38        auth = Authenticator()
39        assert isinstance(auth, Authenticator)
40
41
42class DummyAuthenticatorTests(unittest.TestCase):
43
44    def test_create(self):
45        # we can create DummyAuthenticator instances
46        auth = DummyAuthenticator()
47        assert isinstance(auth, DummyAuthenticator)
48
49    def test_check_credentials(self):
50        # we can succeed with 'bird'/'bebop'. Others will fail.
51        auth = DummyAuthenticator()
52        result1 = auth.check_credentials('bird', 'bebop')
53        assert result1 == (True, '')
54        result2 = auth.check_credentials('foo', 'bar')
55        assert result2 == (False, 'Invalid username or password.')
Note: See TracBrowser for help on using the repository browser.