@@ -47,11 +47,13 @@ def assert_redirect_to_idp(self, redirect_response, idp_conf):
47
47
assert redirect_location == idp_conf ["service" ]["idp" ]["endpoints" ]["single_sign_on_service" ][0 ][0 ]
48
48
assert "SAMLRequest" in parse_qs (parsed .query )
49
49
50
- def assert_redirect_to_discovery_server (self , redirect_response , sp_conf ):
50
+ def assert_redirect_to_discovery_server (
51
+ self , redirect_response , sp_conf , expected_discosrv_url
52
+ ):
51
53
assert redirect_response .status == "303 See Other"
52
54
parsed = urlparse (redirect_response .message )
53
55
redirect_location = "{parsed.scheme}://{parsed.netloc}{parsed.path}" .format (parsed = parsed )
54
- assert redirect_location == DISCOSRV_URL
56
+ assert redirect_location == expected_discosrv_url
55
57
56
58
request_params = dict (parse_qsl (parsed .query ))
57
59
assert request_params ["return" ] == sp_conf ["service" ]["sp" ]["endpoints" ]["discovery_response" ][0 ][0 ]
@@ -99,7 +101,15 @@ def get_path_from_url(url):
99
101
100
102
def test_start_auth_defaults_to_redirecting_to_discovery_server (self , context , sp_conf ):
101
103
resp = self .samlbackend .start_auth (context , InternalData ())
102
- self .assert_redirect_to_discovery_server (resp , sp_conf )
104
+ self .assert_redirect_to_discovery_server (resp , sp_conf , DISCOSRV_URL )
105
+
106
+ def test_discovery_server_set_in_context (self , context , sp_conf ):
107
+ discosrv_url = 'https://my.org/saml_discovery_service'
108
+ context .decorate (
109
+ SAMLBackend .KEY_SAML_DISCOVERY_SERVICE_URL , discosrv_url
110
+ )
111
+ resp = self .samlbackend .start_auth (context , InternalData ())
112
+ self .assert_redirect_to_discovery_server (resp , sp_conf , discosrv_url )
103
113
104
114
def test_full_flow (self , context , idp_conf , sp_conf ):
105
115
test_state_key = "test_state_key_456afgrh"
@@ -110,7 +120,7 @@ def test_full_flow(self, context, idp_conf, sp_conf):
110
120
111
121
# start auth flow (redirecting to discovery server)
112
122
resp = self .samlbackend .start_auth (context , InternalData ())
113
- self .assert_redirect_to_discovery_server (resp , sp_conf )
123
+ self .assert_redirect_to_discovery_server (resp , sp_conf , DISCOSRV_URL )
114
124
115
125
# fake response from discovery server
116
126
disco_resp = parse_qs (urlparse (resp .message ).query )
@@ -166,7 +176,7 @@ def test_always_redirect_to_discovery_service_if_using_mdq(self, context, sp_con
166
176
samlbackend = SAMLBackend (None , INTERNAL_ATTRIBUTES , {"sp_config" : sp_conf , "disco_srv" : DISCOSRV_URL ,},
167
177
"base_url" , "saml_backend" )
168
178
resp = samlbackend .start_auth (context , InternalData ())
169
- self .assert_redirect_to_discovery_server (resp , sp_conf )
179
+ self .assert_redirect_to_discovery_server (resp , sp_conf , DISCOSRV_URL )
170
180
171
181
def test_authn_request (self , context , idp_conf ):
172
182
resp = self .samlbackend .authn_request (context , idp_conf ["entityid" ])
0 commit comments