|
2 | 2 | # -*- coding: utf-8 -*-
|
3 | 3 |
|
4 | 4 | from base64 import encodebytes as b64encode
|
| 5 | +from base64 import decodebytes as b64decode |
5 | 6 | import uuid
|
6 | 7 | import six
|
7 | 8 | from six.moves.urllib import parse
|
|
51 | 52 | "authn_auth": "http://www.example.com/login"
|
52 | 53 | }
|
53 | 54 |
|
54 |
| - |
55 | 55 | def generate_cert():
|
56 | 56 | sn = uuid.uuid4().urn
|
57 | 57 | cert_info = {
|
@@ -413,6 +413,36 @@ def test_sign_auth_request_0(self):
|
413 | 413 | except Exception: # missing certificate
|
414 | 414 | self.client.sec.verify_signature(ar_str, node_name=class_name(ar))
|
415 | 415 |
|
| 416 | + def test_logout_response(self): |
| 417 | + req_id, req = self.server.create_logout_request( |
| 418 | + "http://localhost:8088/slo", "urn:mace:example.com:saml:roland:sp", |
| 419 | + name_id=nid, reason="Tired", expire=in_a_while(minutes=15), |
| 420 | + session_indexes=["_foo"]) |
| 421 | + |
| 422 | + info = self.client.apply_binding( |
| 423 | + BINDING_HTTP_REDIRECT, req, destination="", |
| 424 | + relay_state="relay2") |
| 425 | + loc = info["headers"][0][1] |
| 426 | + qs = parse.parse_qs(loc[1:]) |
| 427 | + samlreq = qs['SAMLRequest'][0] |
| 428 | + resphttp = self.client.handle_logout_request(samlreq, nid, |
| 429 | + BINDING_HTTP_REDIRECT) |
| 430 | + _dic = unpack_form(resphttp['data'], "SAMLResponse") |
| 431 | + xml = b64decode(_dic['SAMLResponse'].encode('UTF-8')) |
| 432 | + |
| 433 | + # Signature found |
| 434 | + assert xml.decode('UTF-8').find(r"Signature") > 0 |
| 435 | + |
| 436 | + # Try again with logout_responses_signed=False |
| 437 | + self.client.logout_responses_signed = False |
| 438 | + resphttp = self.client.handle_logout_request(samlreq, nid, |
| 439 | + BINDING_HTTP_REDIRECT) |
| 440 | + _dic = unpack_form(resphttp['data'], "SAMLResponse") |
| 441 | + xml = b64decode(_dic['SAMLResponse'].encode('UTF-8')) |
| 442 | + |
| 443 | + # Signature not found |
| 444 | + assert xml.decode('UTF-8').find(r"Signature") < 0 |
| 445 | + |
416 | 446 | def test_create_logout_request(self):
|
417 | 447 | req_id, req = self.client.create_logout_request(
|
418 | 448 | "http://localhost:8088/slo", "urn:mace:example.com:saml:roland:idp",
|
|
0 commit comments