Skip to content

Commit df87721

Browse files
committed
Check other user session in CIS2 logout system spec
Add some checks to the back channel logout system spec to ensure that only the user specified in the logout token is logged out, and all other users remain logged in.
1 parent ca829c8 commit df87721

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

manage_breast_screening/tests/system/test_cis2_back_channel_logout.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ def around_each(self):
5656

5757
def test_back_channel_logout_invalidates_user_sessions(self):
5858
self.given_i_am_signed_in()
59+
self.and_someone_else_is_signed_in()
5960
self.and_there_is_a_cis2_logout_token()
6061
self.when_the_back_channel_logout_endpoint_is_called()
6162
self.then_i_am_logged_out()
@@ -68,14 +69,22 @@ def test_back_channel_logout_with_expired_token_is_rejected(self):
6869

6970
def given_i_am_signed_in(self):
7071
User = get_user_model()
71-
self.user_id = "user-123"
72-
user = User.objects.create_user(username=self.user_id, password="irrelevant")
72+
self.user = User.objects.create_user(username="user-123", password="irrelevant")
7373

74-
self.login_as_user(user)
74+
self.login_as_user(self.user)
7575
self.page.goto(self.live_server_url + reverse("clinics:index"))
7676
header = self.page.get_by_role("navigation")
7777
expect(header.get_by_text("Log out")).to_be_visible()
7878

79+
def and_someone_else_is_signed_in(self):
80+
User = get_user_model()
81+
self.another_user = User.objects.create_user(
82+
username="another-user", password="irrelevant"
83+
)
84+
# Log in with a different session
85+
client = TestClient()
86+
client.login(username=self.another_user.username, password="irrelevant")
87+
7988
def and_there_is_a_cis2_logout_token(self):
8089
self.token = self._create_logout_token()
8190

@@ -96,9 +105,8 @@ def when_the_back_channel_logout_endpoint_is_called(self):
96105
def then_i_am_logged_out(self):
97106
assert self.response.status_code == 200
98107

99-
User = get_user_model()
100-
user = User.objects.get(username=self.user_id)
101-
assert user.session_set.all().count() == 0
108+
assert self.user.session_set.all().count() == 0
109+
assert self.another_user.session_set.all().count() == 1
102110

103111
self.page.goto(self.live_server_url + reverse("home"))
104112
header = self.page.get_by_role("navigation")
@@ -109,9 +117,7 @@ def then_the_request_is_rejected_and_i_remain_logged_in(self):
109117
assert self.response.status_code == 400
110118

111119
# Session for the user should still exist
112-
User = get_user_model()
113-
user = User.objects.get(username=self.user_id)
114-
assert user.session_set.all().count() == 1
120+
assert self.user.session_set.all().count() == 1
115121

116122
# UI should still show user as logged in
117123
self.page.goto(self.live_server_url + reverse("home"))
@@ -127,7 +133,7 @@ def _create_logout_token(self, overrides=None):
127133
"iat": now,
128134
"exp": now + 300,
129135
"events": {"http://schemas.openid.net/event/backchannel-logout": {}},
130-
"sub": self.user_id, # We currently key on sub to find the local user
136+
"sub": self.user.username, # We currently key on sub to find the local user
131137
"sid": "not-used",
132138
"jti": "not-used",
133139
}

0 commit comments

Comments
 (0)