diff options
| author | Theron Luhn <theron@luhn.com> | 2019-02-17 16:38:53 -0800 |
|---|---|---|
| committer | Theron Luhn <theron@luhn.com> | 2019-02-17 16:38:53 -0800 |
| commit | 4c3c826ca9a6069f47fee439576966cf625df528 (patch) | |
| tree | 63ead5676ac47a2caa585f51e914d75b855b6bbe /tests | |
| parent | a6234e4e19efab838b202d0935de0de92c2ee00f (diff) | |
| download | pyramid-4c3c826ca9a6069f47fee439576966cf625df528.tar.gz pyramid-4c3c826ca9a6069f47fee439576966cf625df528.tar.bz2 pyramid-4c3c826ca9a6069f47fee439576966cf625df528.zip | |
Implement legacy security policy.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/test_security.py | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/tests/test_security.py b/tests/test_security.py index 8b8028f61..ee4340ced 100644 --- a/tests/test_security.py +++ b/tests/test_security.py @@ -473,6 +473,58 @@ class TestHasPermission(unittest.TestCase): self.assertRaises(AttributeError, request.has_permission, 'view') +class TestLegacySecurityPolicy(unittest.TestCase): + def setUp(self): + testing.setUp() + + def tearDown(self): + testing.tearDown() + + def test_identity(self): + from pyramid.security import LegacySecurityPolicy + + request = _makeRequest() + policy = LegacySecurityPolicy() + _registerAuthenticationPolicy(request.registry, 'userid') + + self.assertEqual(policy.identify(request), 'userid') + + def test_remember(self): + from pyramid.security import LegacySecurityPolicy + + request = _makeRequest() + policy = LegacySecurityPolicy() + _registerAuthenticationPolicy(request.registry, None) + + self.assertEqual( + policy.remember(request, 'userid'), [('X-Pyramid-Test', 'userid')] + ) + + def test_forget(self): + from pyramid.security import LegacySecurityPolicy + + request = _makeRequest() + policy = LegacySecurityPolicy() + _registerAuthenticationPolicy(request.registry, None) + + self.assertEqual( + policy.forget(request), [('X-Pyramid-Test', 'logout')] + ) + + def test_permits(self): + from pyramid.security import LegacySecurityPolicy + + request = _makeRequest() + policy = LegacySecurityPolicy() + _registerAuthenticationPolicy(request.registry, ['p1', 'p2']) + _registerAuthorizationPolicy(request.registry, True) + + self.assertIs( + policy.permits(request, request.context, 'userid', 'permission'), + True, + ) + + _TEST_HEADER = 'X-Pyramid-Test' |
