Skip to content

Commit 50b2963

Browse files
committed
Unit test for logout_responses_signed
1 parent 60476ae commit 50b2963

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

tests/server_conf.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
"required_attributes": ["surName", "givenName", "mail"],
1515
"optional_attributes": ["title"],
1616
"idp": ["urn:mace:example.com:saml:roland:idp"],
17+
"logout_responses_signed": True,
18+
"logout_requests_signed": True,
1719
"requested_attributes": [
1820
{
1921
"name": "urn:oid:1.3.6.1.4.1.5923.1.1.1.2",

tests/test_51_client.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# -*- coding: utf-8 -*-
33

44
from base64 import encodebytes as b64encode
5+
from base64 import decodebytes as b64decode
56
import uuid
67
import six
78
from six.moves.urllib import parse
@@ -51,7 +52,6 @@
5152
"authn_auth": "http://www.example.com/login"
5253
}
5354

54-
5555
def generate_cert():
5656
sn = uuid.uuid4().urn
5757
cert_info = {
@@ -413,6 +413,36 @@ def test_sign_auth_request_0(self):
413413
except Exception: # missing certificate
414414
self.client.sec.verify_signature(ar_str, node_name=class_name(ar))
415415

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+
416446
def test_create_logout_request(self):
417447
req_id, req = self.client.create_logout_request(
418448
"http://localhost:8088/slo", "urn:mace:example.com:saml:roland:idp",

0 commit comments

Comments
 (0)