|
21 | 21 | from saml2 import samlp |
22 | 22 | from saml2 import sigver |
23 | 23 | from saml2 import s_utils |
| 24 | +from saml2 import VERSION |
24 | 25 | from saml2.assertion import Assertion |
25 | 26 | from saml2.extension.requested_attributes import RequestedAttributes |
26 | 27 | from saml2.extension.requested_attributes import RequestedAttribute |
|
40 | 41 | from saml2.sigver import SignatureError, SigverError |
41 | 42 | from saml2.s_utils import do_attribute_statement |
42 | 43 | from saml2.s_utils import factory |
43 | | -from saml2.time_util import in_a_while, a_while_ago |
| 44 | +from saml2.s_utils import sid |
| 45 | +from saml2.time_util import in_a_while |
| 46 | +from saml2.time_util import a_while_ago |
| 47 | +from saml2.time_util import instant |
44 | 48 |
|
45 | 49 | from defusedxml.common import EntitiesForbidden |
46 | 50 |
|
|
53 | 57 | "authn_auth": "http://www.example.com/login" |
54 | 58 | } |
55 | 59 |
|
| 60 | +def response_factory(**kwargs): |
| 61 | + response = samlp.Response(id=sid(), version=VERSION, issue_instant=instant()) |
| 62 | + |
| 63 | + for key, val in kwargs.items(): |
| 64 | + setattr(response, key, val) |
| 65 | + |
| 66 | + return response |
| 67 | + |
56 | 68 | def generate_cert(): |
57 | 69 | sn = uuid.uuid4().urn |
58 | 70 | cert_info = { |
@@ -943,18 +955,19 @@ def test_sign_then_encrypt_assertion(self): |
943 | 955 | # Create an Assertion instance from the signed assertion |
944 | 956 | _ass = saml.assertion_from_string(sigass) |
945 | 957 |
|
946 | | - response = sigver.response_factory( |
| 958 | + response = response_factory( |
947 | 959 | in_response_to="_012345", |
948 | 960 | destination="https:#www.example.com", |
949 | 961 | status=s_utils.success_status_factory(), |
950 | 962 | issuer=self.server._issuer(), |
951 | 963 | assertion=_ass |
952 | 964 | ) |
953 | 965 |
|
954 | | - enctext = _sec.crypto.encrypt_assertion(response, |
955 | | - self.client.sec.encryption_keypairs[ |
956 | | - 0]["cert_file"], |
957 | | - pre_encryption_part()) |
| 966 | + enctext = _sec.crypto.encrypt_assertion( |
| 967 | + response, |
| 968 | + self.client.sec.encryption_keypairs[0]["cert_file"], |
| 969 | + pre_encryption_part(), |
| 970 | + ) |
958 | 971 |
|
959 | 972 | seresp = samlp.response_from_string(enctext) |
960 | 973 |
|
@@ -1023,7 +1036,7 @@ def test_sign_then_encrypt_assertion2(self): |
1023 | 1036 | node_id=assertion.id) |
1024 | 1037 |
|
1025 | 1038 | sigass = rm_xmltag(sigass) |
1026 | | - response = sigver.response_factory( |
| 1039 | + response = response_factory( |
1027 | 1040 | in_response_to="_012345", |
1028 | 1041 | destination="http://lingon.catalogix.se:8087/", |
1029 | 1042 | status=s_utils.success_status_factory(), |
@@ -1116,7 +1129,7 @@ def test_sign_then_encrypt_assertion_advice_1(self): |
1116 | 1129 | assertion.advice.encrypted_assertion[0].add_extension_element( |
1117 | 1130 | a_assertion) |
1118 | 1131 |
|
1119 | | - response = sigver.response_factory( |
| 1132 | + response = response_factory( |
1120 | 1133 | in_response_to="_012345", |
1121 | 1134 | destination="http://lingon.catalogix.se:8087/", |
1122 | 1135 | status=s_utils.success_status_factory(), |
@@ -1267,7 +1280,7 @@ def test_sign_then_encrypt_assertion_advice_2(self): |
1267 | 1280 | assertion_2.signature = sigver.pre_signature_part(assertion_2.id, |
1268 | 1281 | _sec.my_cert, 1) |
1269 | 1282 |
|
1270 | | - response = sigver.response_factory( |
| 1283 | + response = response_factory( |
1271 | 1284 | in_response_to="_012345", |
1272 | 1285 | destination="http://lingon.catalogix.se:8087/", |
1273 | 1286 | status=s_utils.success_status_factory(), |
@@ -2560,7 +2573,7 @@ def test_sign_then_encrypt_assertion(self): |
2560 | 2573 | # Create an Assertion instance from the signed assertion |
2561 | 2574 | _ass = saml.assertion_from_string(sigass) |
2562 | 2575 |
|
2563 | | - response = sigver.response_factory( |
| 2576 | + response = response_factory( |
2564 | 2577 | in_response_to="_012345", |
2565 | 2578 | destination="https:#www.example.com", |
2566 | 2579 | status=s_utils.success_status_factory(), |
@@ -2640,7 +2653,7 @@ def test_sign_then_encrypt_assertion2(self): |
2640 | 2653 | node_id=assertion.id) |
2641 | 2654 |
|
2642 | 2655 | sigass = rm_xmltag(sigass) |
2643 | | - response = sigver.response_factory( |
| 2656 | + response = response_factory( |
2644 | 2657 | in_response_to="_012345", |
2645 | 2658 | destination="http://lingon.catalogix.se:8087/", |
2646 | 2659 | status=s_utils.success_status_factory(), |
@@ -2733,7 +2746,7 @@ def test_sign_then_encrypt_assertion_advice_1(self): |
2733 | 2746 | assertion.advice.encrypted_assertion[0].add_extension_element( |
2734 | 2747 | a_assertion) |
2735 | 2748 |
|
2736 | | - response = sigver.response_factory( |
| 2749 | + response = response_factory( |
2737 | 2750 | in_response_to="_012345", |
2738 | 2751 | destination="http://lingon.catalogix.se:8087/", |
2739 | 2752 | status=s_utils.success_status_factory(), |
@@ -2885,7 +2898,7 @@ def test_sign_then_encrypt_assertion_advice_2(self): |
2885 | 2898 | assertion_2.signature = sigver.pre_signature_part(assertion_2.id, |
2886 | 2899 | _sec.my_cert, 1) |
2887 | 2900 |
|
2888 | | - response = sigver.response_factory( |
| 2901 | + response = response_factory( |
2889 | 2902 | in_response_to="_012345", |
2890 | 2903 | destination="http://lingon.catalogix.se:8087/", |
2891 | 2904 | status=s_utils.success_status_factory(), |
|
0 commit comments