@@ -47,11 +47,15 @@ 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 ,
52
+ redirect_response ,
53
+ sp_conf ,
54
+ expected_discosrv_url ):
51
55
assert redirect_response .status == "303 See Other"
52
56
parsed = urlparse (redirect_response .message )
53
57
redirect_location = "{parsed.scheme}://{parsed.netloc}{parsed.path}" .format (parsed = parsed )
54
- assert redirect_location == DISCOSRV_URL
58
+ assert redirect_location == expected_discosrv_url
55
59
56
60
request_params = dict (parse_qsl (parsed .query ))
57
61
assert request_params ["return" ] == sp_conf ["service" ]["sp" ]["endpoints" ]["discovery_response" ][0 ][0 ]
@@ -99,7 +103,15 @@ def get_path_from_url(url):
99
103
100
104
def test_start_auth_defaults_to_redirecting_to_discovery_server (self , context , sp_conf ):
101
105
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 )
103
115
104
116
def test_full_flow (self , context , idp_conf , sp_conf ):
105
117
test_state_key = "test_state_key_456afgrh"
@@ -110,7 +122,7 @@ def test_full_flow(self, context, idp_conf, sp_conf):
110
122
111
123
# start auth flow (redirecting to discovery server)
112
124
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 )
114
126
115
127
# fake response from discovery server
116
128
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
166
178
samlbackend = SAMLBackend (None , INTERNAL_ATTRIBUTES , {"sp_config" : sp_conf , "disco_srv" : DISCOSRV_URL ,},
167
179
"base_url" , "saml_backend" )
168
180
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 )
170
182
171
183
def test_authn_request (self , context , idp_conf ):
172
184
resp = self .samlbackend .authn_request (context , idp_conf ["entityid" ])
0 commit comments