diff options
author | Ivan Kanakarakis <ivan.kanak@gmail.com> | 2020-12-07 15:43:03 +0200 |
---|---|---|
committer | Ivan Kanakarakis <ivan.kanak@gmail.com> | 2020-12-07 22:46:36 +0200 |
commit | 68d3989ed5c34d94178881e600cc4c3224965aec (patch) | |
tree | b0027984a18123417511ada30d0960fbf0a30304 | |
parent | 017092fc5c7988c36e1855f941508f9e92fa2a53 (diff) | |
download | pysaml2-68d3989ed5c34d94178881e600cc4c3224965aec.tar.gz |
Remove unneeded response_factory helper
Signed-off-by: Ivan Kanakarakis <ivan.kanak@gmail.com>
-rw-r--r-- | src/saml2/entity.py | 9 | ||||
-rw-r--r-- | src/saml2/sigver.py | 17 | ||||
-rw-r--r-- | tests/test_50_server.py | 15 | ||||
-rw-r--r-- | tests/test_51_client.py | 39 |
4 files changed, 43 insertions, 37 deletions
diff --git a/src/saml2/entity.py b/src/saml2/entity.py index a619882b..5320ab6a 100644 --- a/src/saml2/entity.py +++ b/src/saml2/entity.py @@ -62,7 +62,6 @@ from saml2 import class_name from saml2.config import config_factory from saml2.httpbase import HTTPBase from saml2.sigver import security_context -from saml2.sigver import response_factory from saml2.sigver import SigverError from saml2.sigver import SignatureError from saml2.sigver import make_temp @@ -730,10 +729,10 @@ class Entity(HTTPBase): _issuer = self._issuer(issuer) - response = response_factory(issuer=_issuer, - in_response_to=in_response_to, - status=status, sign_alg=sign_alg, - digest_alg=digest_alg) + response = samlp.Response(id=sid(), version=VERSION, issue_instant=instant()) + response.issuer = _issuer + response.in_response_to = in_response_to + response.status = status if consumer_url: response.destination = consumer_url diff --git a/src/saml2/sigver.py b/src/saml2/sigver.py index b8e924c2..d4ba8712 100644 --- a/src/saml2/sigver.py +++ b/src/saml2/sigver.py @@ -1878,23 +1878,6 @@ def pre_encrypt_assertion(response): return response -def response_factory(sign=False, encrypt=False, sign_alg=None, digest_alg=None, - **kwargs): - response = samlp.Response(id=sid(), version=VERSION, - issue_instant=instant()) - - if sign: - response.signature = pre_signature_part( - kwargs['id'], sign_alg=sign_alg, digest_alg=digest_alg) - if encrypt: - pass - - for key, val in kwargs.items(): - setattr(response, key, val) - - return response - - if __name__ == '__main__': import argparse diff --git a/tests/test_50_server.py b/tests/test_50_server.py index 7ee82499..dfc24eee 100644 --- a/tests/test_50_server.py +++ b/tests/test_50_server.py @@ -23,12 +23,15 @@ from saml2 import extension_elements_to_elements from saml2 import s_utils from saml2 import sigver from saml2 import time_util +from saml2 import VERSION from saml2.s_utils import OtherError from saml2.s_utils import do_attribute_statement from saml2.s_utils import factory +from saml2.s_utils import sid from saml2.soap import make_soap_enveloped_saml_thingy from saml2 import BINDING_HTTP_POST from saml2 import BINDING_HTTP_REDIRECT +from saml2.time_util import instant from pytest import raises from pathutils import full_path @@ -44,6 +47,14 @@ AUTHN = { } +def response_factory(**kwargs): + response = samlp.Response(id=sid(), version=VERSION, issue_instant=instant()) + + for key, val in kwargs.items(): + setattr(response, key, val) + + return response + def _eq(l1, l2): return set(l1) == set(l2) @@ -179,7 +190,7 @@ class TestServer1(): assert subject.name_id.format == saml.NAMEID_FORMAT_TRANSIENT def test_response(self): - response = sigver.response_factory( + response = response_factory( in_response_to="_012345", destination="https:#www.example.com", status=s_utils.success_status_factory(), @@ -1239,7 +1250,7 @@ class TestServer1NonAsciiAva(): assert subject.name_id.format == saml.NAMEID_FORMAT_TRANSIENT def test_response(self): - response = sigver.response_factory( + response = response_factory( in_response_to="_012345", destination="https:#www.example.com", status=s_utils.success_status_factory(), diff --git a/tests/test_51_client.py b/tests/test_51_client.py index a20cf941..c82917cd 100644 --- a/tests/test_51_client.py +++ b/tests/test_51_client.py @@ -21,6 +21,7 @@ from saml2 import saml from saml2 import samlp from saml2 import sigver from saml2 import s_utils +from saml2 import VERSION from saml2.assertion import Assertion from saml2.extension.requested_attributes import RequestedAttributes from saml2.extension.requested_attributes import RequestedAttribute @@ -40,7 +41,10 @@ from saml2.sigver import verify_redirect_signature from saml2.sigver import SignatureError, SigverError from saml2.s_utils import do_attribute_statement from saml2.s_utils import factory -from saml2.time_util import in_a_while, a_while_ago +from saml2.s_utils import sid +from saml2.time_util import in_a_while +from saml2.time_util import a_while_ago +from saml2.time_util import instant from defusedxml.common import EntitiesForbidden @@ -53,6 +57,14 @@ AUTHN = { "authn_auth": "http://www.example.com/login" } +def response_factory(**kwargs): + response = samlp.Response(id=sid(), version=VERSION, issue_instant=instant()) + + for key, val in kwargs.items(): + setattr(response, key, val) + + return response + def generate_cert(): sn = uuid.uuid4().urn cert_info = { @@ -943,7 +955,7 @@ class TestClient: # Create an Assertion instance from the signed assertion _ass = saml.assertion_from_string(sigass) - response = sigver.response_factory( + response = response_factory( in_response_to="_012345", destination="https:#www.example.com", status=s_utils.success_status_factory(), @@ -951,10 +963,11 @@ class TestClient: assertion=_ass ) - enctext = _sec.crypto.encrypt_assertion(response, - self.client.sec.encryption_keypairs[ - 0]["cert_file"], - pre_encryption_part()) + enctext = _sec.crypto.encrypt_assertion( + response, + self.client.sec.encryption_keypairs[0]["cert_file"], + pre_encryption_part(), + ) seresp = samlp.response_from_string(enctext) @@ -1023,7 +1036,7 @@ class TestClient: node_id=assertion.id) sigass = rm_xmltag(sigass) - response = sigver.response_factory( + response = response_factory( in_response_to="_012345", destination="http://lingon.catalogix.se:8087/", status=s_utils.success_status_factory(), @@ -1116,7 +1129,7 @@ class TestClient: assertion.advice.encrypted_assertion[0].add_extension_element( a_assertion) - response = sigver.response_factory( + response = response_factory( in_response_to="_012345", destination="http://lingon.catalogix.se:8087/", status=s_utils.success_status_factory(), @@ -1267,7 +1280,7 @@ class TestClient: assertion_2.signature = sigver.pre_signature_part(assertion_2.id, _sec.my_cert, 1) - response = sigver.response_factory( + response = response_factory( in_response_to="_012345", destination="http://lingon.catalogix.se:8087/", status=s_utils.success_status_factory(), @@ -2560,7 +2573,7 @@ class TestClientNonAsciiAva: # Create an Assertion instance from the signed assertion _ass = saml.assertion_from_string(sigass) - response = sigver.response_factory( + response = response_factory( in_response_to="_012345", destination="https:#www.example.com", status=s_utils.success_status_factory(), @@ -2640,7 +2653,7 @@ class TestClientNonAsciiAva: node_id=assertion.id) sigass = rm_xmltag(sigass) - response = sigver.response_factory( + response = response_factory( in_response_to="_012345", destination="http://lingon.catalogix.se:8087/", status=s_utils.success_status_factory(), @@ -2733,7 +2746,7 @@ class TestClientNonAsciiAva: assertion.advice.encrypted_assertion[0].add_extension_element( a_assertion) - response = sigver.response_factory( + response = response_factory( in_response_to="_012345", destination="http://lingon.catalogix.se:8087/", status=s_utils.success_status_factory(), @@ -2885,7 +2898,7 @@ class TestClientNonAsciiAva: assertion_2.signature = sigver.pre_signature_part(assertion_2.id, _sec.my_cert, 1) - response = sigver.response_factory( + response = response_factory( in_response_to="_012345", destination="http://lingon.catalogix.se:8087/", status=s_utils.success_status_factory(), |