Skip to content

Commit f47710d

Browse files
committed
Add test for setting discovery service in context
Added a test for the SAMLBackend for when the discovery service URL is set in the context.
1 parent ebb6d35 commit f47710d

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

tests/satosa/backends/test_saml2.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,15 @@ def assert_redirect_to_idp(self, redirect_response, idp_conf):
4747
assert redirect_location == idp_conf["service"]["idp"]["endpoints"]["single_sign_on_service"][0][0]
4848
assert "SAMLRequest" in parse_qs(parsed.query)
4949

50-
def assert_redirect_to_discovery_server(self, redirect_response, sp_conf):
50+
def assert_redirect_to_discovery_server(
51+
self,
52+
redirect_response,
53+
sp_conf,
54+
expected_discosrv_url):
5155
assert redirect_response.status == "303 See Other"
5256
parsed = urlparse(redirect_response.message)
5357
redirect_location = "{parsed.scheme}://{parsed.netloc}{parsed.path}".format(parsed=parsed)
54-
assert redirect_location == DISCOSRV_URL
58+
assert redirect_location == expected_discosrv_url
5559

5660
request_params = dict(parse_qsl(parsed.query))
5761
assert request_params["return"] == sp_conf["service"]["sp"]["endpoints"]["discovery_response"][0][0]
@@ -99,7 +103,15 @@ def get_path_from_url(url):
99103

100104
def test_start_auth_defaults_to_redirecting_to_discovery_server(self, context, sp_conf):
101105
resp = self.samlbackend.start_auth(context, InternalData())
102-
self.assert_redirect_to_discovery_server(resp, sp_conf)
106+
self.assert_redirect_to_discovery_server(resp, sp_conf, DISCOSRV_URL)
107+
108+
def test_discovery_server_set_in_context(self, context, sp_conf):
109+
discosrv_url = 'https://my.org/saml_discovery_service'
110+
context.decorate(
111+
SAMLBackend.KEY_SAML_DISCOVERY_SERVICE_URL,
112+
discosrv_url)
113+
resp = self.samlbackend.start_auth(context, InternalData())
114+
self.assert_redirect_to_discovery_server(resp, sp_conf, discosrv_url)
103115

104116
def test_full_flow(self, context, idp_conf, sp_conf):
105117
test_state_key = "test_state_key_456afgrh"
@@ -110,7 +122,7 @@ def test_full_flow(self, context, idp_conf, sp_conf):
110122

111123
# start auth flow (redirecting to discovery server)
112124
resp = self.samlbackend.start_auth(context, InternalData())
113-
self.assert_redirect_to_discovery_server(resp, sp_conf)
125+
self.assert_redirect_to_discovery_server(resp, sp_conf, DISCOSRV_URL)
114126

115127
# fake response from discovery server
116128
disco_resp = parse_qs(urlparse(resp.message).query)
@@ -166,7 +178,7 @@ def test_always_redirect_to_discovery_service_if_using_mdq(self, context, sp_con
166178
samlbackend = SAMLBackend(None, INTERNAL_ATTRIBUTES, {"sp_config": sp_conf, "disco_srv": DISCOSRV_URL,},
167179
"base_url", "saml_backend")
168180
resp = samlbackend.start_auth(context, InternalData())
169-
self.assert_redirect_to_discovery_server(resp, sp_conf)
181+
self.assert_redirect_to_discovery_server(resp, sp_conf, DISCOSRV_URL)
170182

171183
def test_authn_request(self, context, idp_conf):
172184
resp = self.samlbackend.authn_request(context, idp_conf["entityid"])

0 commit comments

Comments
 (0)