Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit 26d1033

Browse files
committed
Add a test for wrong user returned by SSO
1 parent 4200319 commit 26d1033

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

tests/rest/client/v2_alpha/test_auth.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,3 +457,30 @@ def test_offers_both_flows_for_upgraded_user(self):
457457
self.assertIn({"stages": ["m.login.password"]}, flows)
458458
self.assertIn({"stages": ["m.login.sso"]}, flows)
459459
self.assertEqual(len(flows), 2)
460+
461+
@skip_unless(HAS_OIDC, "requires OIDC")
462+
@override_config({"oidc_config": TEST_OIDC_CONFIG})
463+
def test_ui_auth_fails_for_incorrect_sso_user(self):
464+
"""If the user tries to authenticate with the wrong SSO user, they get an error
465+
"""
466+
# log the user in
467+
login_resp = self.helper.login_via_oidc(UserID.from_string(self.user).localpart)
468+
self.assertEqual(login_resp["user_id"], self.user)
469+
470+
# start a UI Auth flow by attempting to delete a device
471+
channel = self.delete_device(self.user_tok, self.device_id, 401)
472+
473+
flows = channel.json_body["flows"]
474+
self.assertIn({"stages": ["m.login.sso"]}, flows)
475+
session_id = channel.json_body["session"]
476+
477+
# do the OIDC auth, but auth as the wrong user
478+
channel = self.helper.auth_via_oidc("wrong_user", ui_auth_session_id=session_id)
479+
480+
# that should return a failure message
481+
self.assertSubstring("We were unable to validate", channel.text_body)
482+
483+
# ... and the delete op should now fail with a 403
484+
self.delete_device(
485+
self.user_tok, self.device_id, 403, body={"auth": {"session": session_id}}
486+
)

0 commit comments

Comments
 (0)