Coverage for tests/tests_authentication.py: 100%
28 statements
« prev ^ index » next coverage.py v7.15.0, created at 2026-07-08 12:33 +0000
« prev ^ index » next coverage.py v7.15.0, created at 2026-07-08 12:33 +0000
1import unittest
3from webapp.authentication import (
4 SESSION_AUTH_KEYS,
5 SESSION_INTEGRATION_KEYS,
6 SESSION_DATA_KEYS,
7 empty_session,
8 get_authorization_header,
9 is_authenticated,
10 reset_auth_session,
11)
14class TestResetAuthSession(unittest.TestCase):
15 def test_reset_auth_session_clears_auth_keys(self):
16 session = {key: "value" for key in SESSION_AUTH_KEYS}
17 reset_auth_session(session)
18 for key in SESSION_AUTH_KEYS:
19 self.assertNotIn(key, session)
21 def test_reset_auth_session_preserves_integration_keys(self):
22 session = {key: f"{key}-value" for key in SESSION_INTEGRATION_KEYS}
23 reset_auth_session(session)
24 for key in SESSION_INTEGRATION_KEYS:
25 self.assertEqual(session[key], f"{key}-value")
27 def test_empty_session_clears_everything(self):
28 session = {key: "value" for key in SESSION_DATA_KEYS}
29 empty_session(session)
30 for key in SESSION_DATA_KEYS:
31 self.assertNotIn(key, session)
33 def test_session_data_keys_is_union(self):
34 self.assertEqual(
35 set(SESSION_DATA_KEYS),
36 set(SESSION_AUTH_KEYS) | set(SESSION_INTEGRATION_KEYS),
37 )
39 def test_session_keys_are_disjoint(self):
40 self.assertEqual(
41 set(SESSION_AUTH_KEYS).intersection(set(SESSION_INTEGRATION_KEYS)),
42 set(),
43 )
45 def test_get_authorization_header_uses_single_exchanged_macaroon(self):
46 self.assertEqual(
47 get_authorization_header("test-macaroon"),
48 "Macaroon test-macaroon",
49 )
51 def test_is_authenticated_with_exchanged_macaroon(self):
52 self.assertTrue(
53 is_authenticated(
54 {
55 "publisher": {"nickname": "test"},
56 "macaroon_exchanged": "test-macaroon",
57 }
58 )
59 )
61 def test_is_authenticated_with_legacy_macaroons(self):
62 self.assertTrue(
63 is_authenticated(
64 {
65 "publisher": {"nickname": "test"},
66 "macaroons": "legacy-macaroon",
67 }
68 )
69 )