summary refs log tree commit diff
path: root/tests/rest/client/v2_alpha/test_auth.py
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2021-01-15 14:05:55 +0000
committerErik Johnston <erik@matrix.org>2021-01-15 14:05:55 +0000
commit029c9ef967e214cbee7abb3a976031aa1d95970c (patch)
tree1660b11854b6a4e8f4b82cb2cd839b61366ee865 /tests/rest/client/v2_alpha/test_auth.py
parentMerge remote-tracking branch 'origin/develop' into matrix-org-hotfixes (diff)
parentImprove UsernamePickerTestCase (#9112) (diff)
downloadsynapse-029c9ef967e214cbee7abb3a976031aa1d95970c.tar.xz
Merge remote-tracking branch 'origin/develop' into matrix-org-hotfixes
Diffstat (limited to 'tests/rest/client/v2_alpha/test_auth.py')
-rw-r--r--tests/rest/client/v2_alpha/test_auth.py29
1 files changed, 28 insertions, 1 deletions
diff --git a/tests/rest/client/v2_alpha/test_auth.py b/tests/rest/client/v2_alpha/test_auth.py

index 5f6ca23b06..3e8661f9b9 100644 --- a/tests/rest/client/v2_alpha/test_auth.py +++ b/tests/rest/client/v2_alpha/test_auth.py
@@ -411,7 +411,7 @@ class UIAuthTests(unittest.HomeserverTestCase): # run the UIA-via-SSO flow session_id = channel.json_body["session"] channel = self.helper.auth_via_oidc( - remote_user_id=remote_user_id, ui_auth_session_id=session_id + {"sub": remote_user_id}, ui_auth_session_id=session_id ) # that should serve a confirmation page @@ -457,3 +457,30 @@ class UIAuthTests(unittest.HomeserverTestCase): self.assertIn({"stages": ["m.login.password"]}, flows) self.assertIn({"stages": ["m.login.sso"]}, flows) self.assertEqual(len(flows), 2) + + @skip_unless(HAS_OIDC, "requires OIDC") + @override_config({"oidc_config": TEST_OIDC_CONFIG}) + def test_ui_auth_fails_for_incorrect_sso_user(self): + """If the user tries to authenticate with the wrong SSO user, they get an error + """ + # log the user in + login_resp = self.helper.login_via_oidc(UserID.from_string(self.user).localpart) + self.assertEqual(login_resp["user_id"], self.user) + + # start a UI Auth flow by attempting to delete a device + channel = self.delete_device(self.user_tok, self.device_id, 401) + + flows = channel.json_body["flows"] + self.assertIn({"stages": ["m.login.sso"]}, flows) + session_id = channel.json_body["session"] + + # do the OIDC auth, but auth as the wrong user + channel = self.helper.auth_via_oidc("wrong_user", ui_auth_session_id=session_id) + + # that should return a failure message + self.assertSubstring("We were unable to validate", channel.text_body) + + # ... and the delete op should now fail with a 403 + self.delete_device( + self.user_tok, self.device_id, 403, body={"auth": {"session": session_id}} + )