Skip to content

Commit 0d7fa61

Browse files
authored
fix: clear all session data on logout (#5429)
1 parent a3a3ad1 commit 0d7fa61

2 files changed

Lines changed: 21 additions & 5 deletions

File tree

tests/publisher/tests_account_logout.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import responses
22
from tests.publisher.endpoint_testing import BaseTestCases
3+
from webapp.authentication import SESSION_DATA_KEYS
34

45
# Make sure tests fail on stray responses.
56
responses.mock.assert_all_requests_are_fired = True
@@ -13,8 +14,14 @@ def setUp(self):
1314

1415
@responses.activate
1516
def test_logout(self):
17+
with self.client.session_transaction() as session:
18+
for key in SESSION_DATA_KEYS:
19+
session[key] = "MOCK VALUE"
20+
1621
response = self.client.get(self.endpoint_url)
1722

1823
self.assertEqual(302, response.status_code)
1924

2025
self.assertEqual("/", response.location)
26+
27+
self.assertIn("session=;", response.headers.get("Set-Cookie"))

webapp/authentication.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,18 @@
2020
]
2121

2222

23+
SESSION_DATA_KEYS = [
24+
"macaroons",
25+
"macaroon_root",
26+
"macaroon_discharge",
27+
"publisher",
28+
"github_auth_secret",
29+
"developer_token",
30+
"exchanged_developer_token",
31+
"csrf_token",
32+
] # keys for data stored in the session that should be cleared on logout
33+
34+
2335
def get_authorization_header(root, discharge):
2436
"""
2537
Bind root and discharge macaroons and return the authorization header.
@@ -52,11 +64,8 @@ def empty_session(session):
5264
"""
5365
Empty the session, used to logout.
5466
"""
55-
session.pop("macaroons", None)
56-
session.pop("macaroon_root", None)
57-
session.pop("macaroon_discharge", None)
58-
session.pop("publisher", None)
59-
session.pop("github_auth_secret", None)
67+
for key in SESSION_DATA_KEYS:
68+
session.pop(key, None)
6069

6170

6271
def get_caveat_id(root):

0 commit comments

Comments
 (0)