1
1
#!/usr/bin/env python
2
2
# -*- coding: utf-8 -*-
3
- from contextlib import closing
4
- from datetime import datetime
5
- from dateutil import parser
6
- from string import translate , whitespace
7
- from saml2 .authn_context import INTERNETPROTOCOLPASSWORD
8
-
9
- from saml2 .server import Server
10
3
from saml2 .response import authn_response
11
4
from saml2 .config import config_factory
12
5
13
6
from pathutils import dotname , full_path
14
7
15
- # Example SAML response iwth 'holder-of-key' subject confirmtaions
16
- # containing DER-base64 copies (without PEM enclosure) of test_1.crt and test_2.crt
17
8
HOLDER_OF_KEY_RESPONSE_FILE = full_path ("saml_hok.xml" )
18
9
19
- TEST_CERT_1 = full_path ("test_1.crt" )
20
- TEST_CERT_2 = full_path ("test_2.crt" )
21
-
22
10
23
11
class TestHolderOfKeyResponse :
24
12
def test_hok_response_is_parsed (self ):
@@ -34,17 +22,39 @@ def test_hok_response_is_parsed(self):
34
22
35
23
assert resp .get_subject () is not None
36
24
assert len (resp .assertion .subject .subject_confirmation ) == 2
37
- actual_certs = [sc .subject_confirmation_data .key_info [0 ].x509_data [0 ].x509_certificate .text .strip ()
25
+ actual_hok_certs = [sc .subject_confirmation_data .key_info [0 ].x509_data [0 ].x509_certificate .text .strip ()
38
26
for sc in resp .assertion .subject .subject_confirmation ]
39
- expected_certs = [self ._read_cert_without_pem_enclosure (TEST_CERT_1 ),
40
- self ._read_cert_without_pem_enclosure (TEST_CERT_2 )]
41
- assert actual_certs == expected_certs
42
-
43
- def _read_cert_without_pem_enclosure (self , path ):
44
- with open (path , 'r' ) as fp :
45
- lines = fp .readlines ()
46
- lines_without_enclosure = lines [1 :- 1 ]
47
- return '' .join (lines_without_enclosure ).translate (None , whitespace )
27
+ assert actual_hok_certs == self ._expected_hok_certs ()
28
+
29
+ def _expected_hok_certs (self ):
30
+ certs = ["""MIICITCCAYoCAQEwDQYJKoZIhvcNAQELBQAwWDELMAkGA1UEBhMCenoxCzAJBgNV
31
+ BAgMAnp6MQ0wCwYDVQQHDAR6enp6MQ4wDAYDV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ADCBiQKBgQDjW0kJM+4baWKtvO24ZsGXNvNK
48
+ KkwTMz7OW5Z6BRqhSOq2WA0c5NCpMk6rD8Z2OTFEolPojEjf8dVyd/Ds/hrjFKQv
49
+ 8wQgbdXLN51YTIsgd6h+hBJO+vzhl0PT4aT7M0JKo5ALtS6qk4tsworW2BnwyvsG
50
+ SAinwfeWt4t/b1J3kwIDAQABMA0GCSqGSIb3DQEBCwUAA4GBAFtj7WArQQBugmh/
51
+ KQjjlfTQ5A052QeXfgTyO9vv1S6MRIi7qgiaEv49cGXnJv/TWbySkMKObPMUApjg
52
+ 6z8PqcxuShew5FCTkNvwhABFPiyu0fUj3e2FEPHfsBu76jz4ugtmhUqjqhzwFY9c
53
+ tnWRkkl6J0AjM3LnHOSgjNIclDZG""" ]
54
+ for index , item in enumerate (certs ):
55
+ item = item .replace (' ' , '' ).replace ('\n ' , '' )
56
+ certs [index ] = item
57
+ return certs
48
58
49
59
50
60
if __name__ == "__main__" :
0 commit comments