Skip to content

Commit 90358f9

Browse files
Merge pull request #746 from spaceone/apply-binding-status-code
Include status-code in http_info struct Note that, we still need to switch between 302 and 303 depending on the HTTP protocol version (1.1 or newer)
2 parents 344ca99 + 8692440 commit 90358f9

File tree

5 files changed

+22
-15
lines changed

5 files changed

+22
-15
lines changed

src/saml2/entity.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ def apply_binding(self, binding, msg_str, destination="", relay_state="",
241241
if response:
242242
info = self.use_http_artifact(msg_str, destination, relay_state)
243243
info["method"] = "GET"
244-
info["status"] = 302
244+
info["status"] = 302 # TODO: should be 303 on >= HTTP/1.1
245245
else:
246246
info = self.use_http_artifact(msg_str, destination, relay_state)
247247
else:

src/saml2/pack.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def http_form_post_message(message, location, relay_state="",
111111
relay_state_input=relay_state_input,
112112
action=location)
113113

114-
return {"headers": [("Content-type", "text/html")], "data": response}
114+
return {"headers": [("Content-type", "text/html")], "data": response, "status": 200}
115115

116116

117117
def http_post_message(message, relay_state="", typ="SAMLRequest", **kwargs):
@@ -137,7 +137,8 @@ def http_post_message(message, relay_state="", typ="SAMLRequest", **kwargs):
137137
part["RelayState"] = relay_state
138138

139139
return {"headers": [("Content-type", 'application/x-www-form-urlencoded')],
140-
"data": urlencode(part)}
140+
"data": urlencode(part),
141+
"status": 200}
141142

142143

143144
def http_redirect_message(message, location, relay_state="", typ="SAMLRequest",
@@ -197,7 +198,7 @@ def http_redirect_message(message, location, relay_state="", typ="SAMLRequest",
197198
headers = [('Location', str(login_url))]
198199
body = []
199200

200-
return {"headers": headers, "data": body}
201+
return {"headers": headers, "data": body, "status": 303}
201202

202203

203204
DUMMY_NAMESPACE = "http://example.org/"
@@ -257,12 +258,14 @@ def make_soap_enveloped_saml_thingy(thingy, header_parts=None):
257258

258259
def http_soap_message(message):
259260
return {"headers": [("Content-type", "application/soap+xml")],
260-
"data": make_soap_enveloped_saml_thingy(message)}
261+
"data": make_soap_enveloped_saml_thingy(message),
262+
"status": 200}
261263

262264

263265
def http_paos(message, extra=None):
264266
return {"headers": [("Content-type", "application/soap+xml")],
265-
"data": make_soap_enveloped_saml_thingy(message, extra)}
267+
"data": make_soap_enveloped_saml_thingy(message, extra),
268+
"status": 200}
266269

267270

268271
def parse_soap_enveloped_saml(text, body_class, header_class=None):

tests/fakeIDP.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ def unpack_form(_str, ver="SAMLRequest"):
4343

4444

4545
class DummyResponse(object):
46-
def __init__(self, code, data, headers=None):
47-
self.status_code = code
46+
def __init__(self, status, data, headers=None):
47+
self.status_code = status
4848
self.text = data
4949
self.headers = headers or []
5050
self.content = data
@@ -130,7 +130,7 @@ def authn_request_endpoint(self, req, binding, relay_state):
130130
_dict = pack.factory(_binding, response,
131131
resp_args["destination"], relay_state,
132132
"SAMLResponse")
133-
return DummyResponse(200, **_dict)
133+
return DummyResponse(**_dict)
134134

135135
def attribute_query_endpoint(self, xml_str, binding):
136136
if binding == BINDING_SOAP:
@@ -160,7 +160,7 @@ def attribute_query_endpoint(self, xml_str, binding):
160160
else: # Just POST
161161
response = "%s" % attr_resp
162162

163-
return DummyResponse(200, response)
163+
return DummyResponse(status=200, data=response)
164164

165165
def logout_endpoint(self, xml_str, binding):
166166
if binding == BINDING_SOAP:
@@ -185,4 +185,4 @@ def logout_endpoint(self, xml_str, binding):
185185
else: # Just POST
186186
response = "%s" % _resp
187187

188-
return DummyResponse(200, response)
188+
return DummyResponse(status=200, data=response)

tests/test_50_server.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -2311,9 +2311,10 @@ def test_1(self):
23112311
binding, "%s" % response, destination, "relay_state", response=True
23122312
)
23132313

2314-
assert len(http_args) == 4
2314+
assert len(http_args) == 5
23152315
assert http_args["headers"][0][0] == "Location"
23162316
assert http_args["data"] == []
2317+
assert http_args["status"] == 303
23172318
assert http_args['url'] == 'http://lingon.catalogix.se:8087/sloresp'
23182319

23192320
def test_2(self):
@@ -2330,10 +2331,11 @@ def test_2(self):
23302331
binding, "%s" % response, destination, "relay_state", response=True
23312332
)
23322333

2333-
assert len(http_args) == 4
2334+
assert len(http_args) == 5
23342335
assert len(http_args["data"]) > 0
23352336
assert http_args["method"] == "POST"
23362337
assert http_args['url'] == 'http://lingon.catalogix.se:8087/slo'
2338+
assert http_args['status'] == 200
23372339

23382340

23392341
if __name__ == "__main__":

tests/test_51_client.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -3167,9 +3167,10 @@ def test_do_authn(self):
31673167
binding=binding, response_binding=response_binding)
31683168

31693169
assert isinstance(sid, six.string_types)
3170-
assert len(http_args) == 4
3170+
assert len(http_args) == 5
31713171
assert http_args["headers"][0][0] == "Location"
31723172
assert http_args["data"] == []
3173+
assert http_args["status"] == 303
31733174
redirect_url = http_args["headers"][0][1]
31743175
_, _, _, _, qs, _ = parse.urlparse(redirect_url)
31753176
qs_dict = parse.parse_qs(qs)
@@ -3188,9 +3189,10 @@ def test_do_negotiated_authn(self):
31883189

31893190
assert binding == auth_binding
31903191
assert isinstance(sid, six.string_types)
3191-
assert len(http_args) == 4
3192+
assert len(http_args) == 5
31923193
assert http_args["headers"][0][0] == "Location"
31933194
assert http_args["data"] == []
3195+
assert http_args["status"] == 303
31943196
redirect_url = http_args["headers"][0][1]
31953197
_, _, _, _, qs, _ = parse.urlparse(redirect_url)
31963198
qs_dict = parse.parse_qs(qs)

0 commit comments

Comments
 (0)