Skip to content

Commit

Permalink
Fix the rest of the MultiSSOTestCase tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MadLittleMods committed Nov 28, 2024
1 parent d0b1552 commit 4ea1a51
Showing 1 changed file with 74 additions and 2 deletions.
76 changes: 74 additions & 2 deletions tests/rest/client/test_login.py
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,30 @@ def test_multi_sso_redirect_to_cas(self) -> None:
+ "&idp=cas",
shorthand=False,
)
self.assertEqual(channel.code, 302, channel.result)
location_headers = channel.headers.getRawHeaders("Location")
assert location_headers
sso_login_redirect_uri = location_headers[0]

# it should redirect us to the standard login SSO redirect flow
self.assertEqual(
sso_login_redirect_uri,
self.login_sso_redirect_url_builder.build_login_sso_redirect_uri(
idp_id="cas", client_redirect_url=TEST_CLIENT_REDIRECT_URL
),
)

# follow the redirect
#
# We have to make this relative to be compatible with `make_request(...)`
relative_sso_login_redirect_uri = get_relative_uri_from_absolute_uri(
sso_login_redirect_uri
)
channel = self.make_request(
"GET",
relative_sso_login_redirect_uri,
)

self.assertEqual(channel.code, 302, channel.result)
location_headers = channel.headers.getRawHeaders("Location")
assert location_headers
Expand All @@ -770,6 +794,30 @@ def test_multi_sso_redirect_to_saml(self) -> None:
+ urllib.parse.quote_plus(TEST_CLIENT_REDIRECT_URL)
+ "&idp=saml",
)
self.assertEqual(channel.code, 302, channel.result)
location_headers = channel.headers.getRawHeaders("Location")
assert location_headers
sso_login_redirect_uri = location_headers[0]

# it should redirect us to the standard login SSO redirect flow
self.assertEqual(
sso_login_redirect_uri,
self.login_sso_redirect_url_builder.build_login_sso_redirect_uri(
idp_id="saml", client_redirect_url=TEST_CLIENT_REDIRECT_URL
),
)

# follow the redirect
#
# We have to make this relative to be compatible with `make_request(...)`
relative_sso_login_redirect_uri = get_relative_uri_from_absolute_uri(
sso_login_redirect_uri
)
channel = self.make_request(
"GET",
relative_sso_login_redirect_uri,
)

self.assertEqual(channel.code, 302, channel.result)
location_headers = channel.headers.getRawHeaders("Location")
assert location_headers
Expand Down Expand Up @@ -881,12 +929,36 @@ def test_login_via_oidc(self) -> None:
self.assertEqual(chan.json_body["user_id"], "@user1:test")

def test_multi_sso_redirect_to_unknown(self) -> None:
"""An unknown IdP should cause a 400"""
"""An unknown IdP should cause a 404"""
channel = self.make_request(
"GET",
"/_synapse/client/pick_idp?redirectUrl=http://x&idp=xyz",
)
self.assertEqual(channel.code, 400, channel.result)
self.assertEqual(channel.code, 302, channel.result)
location_headers = channel.headers.getRawHeaders("Location")
assert location_headers
sso_login_redirect_uri = location_headers[0]

# it should redirect us to the standard login SSO redirect flow
self.assertEqual(
sso_login_redirect_uri,
self.login_sso_redirect_url_builder.build_login_sso_redirect_uri(
idp_id="xyz", client_redirect_url="http://x"
),
)

# follow the redirect
#
# We have to make this relative to be compatible with `make_request(...)`
relative_sso_login_redirect_uri = get_relative_uri_from_absolute_uri(
sso_login_redirect_uri
)
channel = self.make_request(
"GET",
relative_sso_login_redirect_uri,
)

self.assertEqual(channel.code, 404, channel.result)

def test_client_idp_redirect_to_unknown(self) -> None:
"""If the client tries to pick an unknown IdP, return a 404"""
Expand Down

0 comments on commit 4ea1a51

Please sign in to comment.