Skip to content

Commit 95ffb58

Browse files
committed
added new tests category between "pre" and "post: "mid". added new test cases
1 parent b16009d commit 95ffb58

File tree

4 files changed

+162
-57
lines changed

4 files changed

+162
-57
lines changed

src/saml2test/check.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,28 @@ def _func(self, conv):
213213
return res
214214

215215

216+
class CheckSpHttpResponse500(Error):
217+
""" Checks that the SP's HTTP response status is >= 500. This is useful
218+
to check if the SP correctly flags errors such as an invalid signature
219+
"""
220+
cid = "check-sp-http-response-500"
221+
msg = "SP does not return a HTTP 5xx status when it shold do so."
222+
223+
def _func(self, conv):
224+
_response = conv.last_response
225+
_content = conv.last_response.content
226+
227+
res = {}
228+
if _response.status_code < 500:
229+
self._status = self.status
230+
self._message = self.msg
231+
#res["content"] = _content #too big + charset converstion needed
232+
res["url"] = conv.position
233+
res["http_status"] = _response.status_code
234+
235+
return res
236+
237+
216238
class MissingRedirect(CriticalError):
217239
""" At this point in the flow a redirect back to the client was expected.
218240
"""

src/sp_test/base.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -282,13 +282,6 @@ def send_idp_response(self, req_flow, resp_flow):
282282
:param resp_flow: The flow to prepare the response
283283
:return: The SP's HTTP response on receiving the SAML response
284284
"""
285-
# make sure I got the request I expected
286-
assert isinstance(self.saml_request.message, req._class)
287-
288-
try:
289-
self.test_sequence(req.tests["post"])
290-
except KeyError:
291-
pass
292285

293286
# Pick information from the request that should be in the response
294287
args = self.instance.response_args(self.saml_request.message,
@@ -381,7 +374,7 @@ def send_idp_response(self, req_flow, resp_flow):
381374

382375
self._log_response(self.last_response)
383376

384-
def do_flow(self, flow):
377+
def do_flow(self, flow, mid_tests):
385378
"""
386379
Solicited or 'un-solicited' flows.
387380
@@ -392,21 +385,28 @@ def do_flow(self, flow):
392385
self.wb_send_GET_startpage()
393386
self.intermit(flow[0]._interaction)
394387
self.parse_saml_message()
388+
# make sure I got the request I expected
389+
assert isinstance(self.saml_request.message, flow[1]._class)
390+
try:
391+
self.test_sequence(mid_tests)
392+
except KeyError:
393+
pass
395394
self.send_idp_response(flow[1], flow[2])
396395
if len(flow) == 4:
397396
self.handle_result(flow[3])
398397
else:
399398
self.handle_result()
400399

401400
def do_sequence_and_tests(self, oper, tests=None):
401+
self.current_oper = oper
402402
try:
403403
self.test_sequence(tests["pre"])
404404
except KeyError:
405405
pass
406406

407407
for flow in oper:
408408
try:
409-
self.do_flow(flow)
409+
self.do_flow(flow, tests["mid"])
410410
except InteractionNeeded:
411411
self.test_output.append({"status": INTERACTION,
412412
"message": "see detail log for response content",

src/sp_test/check.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import re
44
import sys
55

6-
from saml2 import BINDING_HTTP_REDIRECT
6+
from saml2 import BINDING_HTTP_POST, BINDING_HTTP_REDIRECT
77
from saml2test.check import Check
88
from saml2test.check import ERROR, INFORMATION, WARNING
99
from saml2test import check
@@ -86,6 +86,15 @@ def _func(self, conv):
8686
if request.signature:
8787
if not self._digest_algo(request.signature, _algs):
8888
return {}
89+
elif conv._binding == BINDING_HTTP_REDIRECT:
90+
self._message = "no digest with redirect binding"
91+
self._status = INFORMATION
92+
return {}
93+
elif conv._binding == BINDING_HTTP_POST:
94+
self._message = "cannot verify digest algorithm: request not signed"
95+
self._status = WARNING
96+
return {}
97+
8998

9099
return {}
91100

@@ -204,6 +213,29 @@ def call_on_redirect(self):
204213
return False
205214

206215

216+
class SetResponseAndAssertionSignaturesFalse(Check):
217+
""" Prepare config to suppress signatures of both response and assertion"""
218+
cid = "set-response-and-assertion-signature-false"
219+
msg = "Prepare config to suppress signatures of both response and assertion"
220+
221+
def _func(self, conv):
222+
conv.json_config['args']['AuthnResponse']['sign_assertion'] = 'never'
223+
conv.json_config['args']['AuthnResponse']['sign_response'] = 'never'
224+
self._status = INFORMATION
225+
return {}
226+
227+
228+
#class SetInvalidIdpKey(Check):
229+
# """ Prepare config to set IDP signing key to some useless key"""
230+
# cid = "set-idp-key-invalid"
231+
# msg = "Prepare config to set IDP signing key invalid"
232+
#
233+
# def _func(self, conv):
234+
# conv.instance.sec.cert_file = conv.instance.config.invalid_idp_cert_file
235+
# conv.instance.sec.key_file = conv.instance.config.invalid_idp_key_file
236+
# return {}
237+
238+
207239
# =============================================================================
208240

209241

0 commit comments

Comments
 (0)