Skip to content

Commit 560f37d

Browse files
Reflow auth_response inline XML
1 parent 0d0c8a3 commit 560f37d

File tree

1 file changed

+44
-2
lines changed

1 file changed

+44
-2
lines changed

djangosaml2/tests/auth_response.py

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,50 @@ def auth_response(session_id, uid):
2222
tomorrow = datetime.datetime.now() + datetime.timedelta(days=1)
2323
yesterday = datetime.datetime.now() - datetime.timedelta(days=1)
2424

25-
saml_response_tpl = """<?xml version='1.0' encoding='UTF-8'?>
26-
<samlp:Response xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Destination="http://sp.example.com/saml2/acs/" ID="id-88b9f586a2a3a639f9327485cc37c40a" InResponseTo="%(session_id)s" IssueInstant="%(timestamp)s" Version="2.0"><saml:Issuer Format="urn:oasis:names:tc:SAML:2.0:nameid-format:entity">https://idp.example.com/simplesaml/saml2/idp/metadata.php</saml:Issuer><samlp:Status><samlp:StatusCode Value="urn:oasis:names:tc:SAML:2.0:status:Success" /></samlp:Status><saml:Assertion ID="id-093952102ceb73436e49cb91c58b0578" IssueInstant="%(timestamp)s" Version="2.0"><saml:Issuer Format="urn:oasis:names:tc:SAML:2.0:nameid-format:entity">https://idp.example.com/simplesaml/saml2/idp/metadata.php</saml:Issuer><saml:Subject><saml:NameID Format="urn:oasis:names:tc:SAML:2.0:nameid-format:transient" NameQualifier="" SPNameQualifier="http://sp.example.com/saml2/metadata/">1f87035b4c1325b296a53d92097e6b3fa36d7e30ee82e3fcb0680d60243c1f03</saml:NameID><saml:SubjectConfirmation Method="urn:oasis:names:tc:SAML:2.0:cm:bearer"><saml:SubjectConfirmationData InResponseTo="%(session_id)s" NotOnOrAfter="%(tomorrow)s" Recipient="http://sp.example.com/saml2/acs/" /></saml:SubjectConfirmation></saml:Subject><saml:Conditions NotBefore="%(yesterday)s" NotOnOrAfter="%(tomorrow)s"><saml:AudienceRestriction><saml:Audience>http://sp.example.com/saml2/metadata/</saml:Audience></saml:AudienceRestriction></saml:Conditions><saml:AuthnStatement AuthnInstant="%(timestamp)s" SessionIndex="%(session_id)s"><saml:AuthnContext><saml:AuthnContextClassRef>urn:oasis:names:tc:SAML:2.0:ac:classes:Password</saml:AuthnContextClassRef></saml:AuthnContext></saml:AuthnStatement><saml:AttributeStatement><saml:Attribute FriendlyName="uid" Name="urn:oid:0.9.2342.19200300.100.1.1" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri"><saml:AttributeValue xsi:nil="true" xsi:type="xs:string">%(uid)s</saml:AttributeValue></saml:Attribute></saml:AttributeStatement></saml:Assertion></samlp:Response>"""
25+
saml_response_tpl = (
26+
"<?xml version='1.0' encoding='UTF-8'?>"
27+
'<samlp:Response xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Destination="http://sp.example.com/saml2/acs/" ID="id-88b9f586a2a3a639f9327485cc37c40a" InResponseTo="%(session_id)s" IssueInstant="%(timestamp)s" Version="2.0">'
28+
'<saml:Issuer Format="urn:oasis:names:tc:SAML:2.0:nameid-format:entity">'
29+
'https://idp.example.com/simplesaml/saml2/idp/metadata.php'
30+
'</saml:Issuer>'
31+
'<samlp:Status>'
32+
'<samlp:StatusCode Value="urn:oasis:names:tc:SAML:2.0:status:Success" />'
33+
'</samlp:Status>'
34+
'<saml:Assertion ID="id-093952102ceb73436e49cb91c58b0578" IssueInstant="%(timestamp)s" Version="2.0">'
35+
'<saml:Issuer Format="urn:oasis:names:tc:SAML:2.0:nameid-format:entity">'
36+
'https://idp.example.com/simplesaml/saml2/idp/metadata.php'
37+
'</saml:Issuer>'
38+
'<saml:Subject>'
39+
'<saml:NameID Format="urn:oasis:names:tc:SAML:2.0:nameid-format:transient" NameQualifier="" SPNameQualifier="http://sp.example.com/saml2/metadata/">'
40+
'1f87035b4c1325b296a53d92097e6b3fa36d7e30ee82e3fcb0680d60243c1f03'
41+
'</saml:NameID>'
42+
'<saml:SubjectConfirmation Method="urn:oasis:names:tc:SAML:2.0:cm:bearer">'
43+
'<saml:SubjectConfirmationData InResponseTo="%(session_id)s" NotOnOrAfter="%(tomorrow)s" Recipient="http://sp.example.com/saml2/acs/" />'
44+
'</saml:SubjectConfirmation>'
45+
'</saml:Subject>'
46+
'<saml:Conditions NotBefore="%(yesterday)s" NotOnOrAfter="%(tomorrow)s">'
47+
'<saml:AudienceRestriction>'
48+
'<saml:Audience>'
49+
'http://sp.example.com/saml2/metadata/'
50+
'</saml:Audience>'
51+
'</saml:AudienceRestriction>'
52+
'</saml:Conditions>'
53+
'<saml:AuthnStatement AuthnInstant="%(timestamp)s" SessionIndex="%(session_id)s">'
54+
'<saml:AuthnContext>'
55+
'<saml:AuthnContextClassRef>'
56+
'urn:oasis:names:tc:SAML:2.0:ac:classes:Password'
57+
'</saml:AuthnContextClassRef>'
58+
'</saml:AuthnContext>'
59+
'</saml:AuthnStatement>'
60+
'<saml:AttributeStatement>'
61+
'<saml:Attribute FriendlyName="uid" Name="urn:oid:0.9.2342.19200300.100.1.1" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri">'
62+
'<saml:AttributeValue xsi:nil="true" xsi:type="xs:string">'
63+
'%(uid)s'
64+
'</saml:AttributeValue>'
65+
'</saml:Attribute>'
66+
'</saml:AttributeStatement>'
67+
'</saml:Assertion>'
68+
'</samlp:Response>')
2769
return saml_response_tpl % {
2870
'uid': uid,
2971
'session_id': session_id,

0 commit comments

Comments
 (0)