[10394] | 1 | import unittest |
---|
| 2 | from waeup.cas.authenticators import ( |
---|
| 3 | get_all_authenticators, get_authenticator, filter_auth_opts, |
---|
| 4 | Authenticator, DummyAuthenticator, |
---|
| 5 | ) |
---|
| 6 | |
---|
| 7 | |
---|
| 8 | class 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 | |
---|
| 34 | class 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 | |
---|
| 42 | class 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') |
---|
[10396] | 53 | assert result1 == (True, '') |
---|
[10394] | 54 | result2 = auth.check_credentials('foo', 'bar') |
---|
[10396] | 55 | assert result2 == (False, 'Invalid username or password.') |
---|