Skip to content

Commit 68d3989

Browse files
committed
Remove unneeded response_factory helper
Signed-off-by: Ivan Kanakarakis <[email protected]>
1 parent 017092f commit 68d3989

File tree

4 files changed

+43
-37
lines changed

4 files changed

+43
-37
lines changed

src/saml2/entity.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@
6262
from saml2.config import config_factory
6363
from saml2.httpbase import HTTPBase
6464
from saml2.sigver import security_context
65-
from saml2.sigver import response_factory
6665
from saml2.sigver import SigverError
6766
from saml2.sigver import SignatureError
6867
from saml2.sigver import make_temp
@@ -730,10 +729,10 @@ def _response(
730729

731730
_issuer = self._issuer(issuer)
732731

733-
response = response_factory(issuer=_issuer,
734-
in_response_to=in_response_to,
735-
status=status, sign_alg=sign_alg,
736-
digest_alg=digest_alg)
732+
response = samlp.Response(id=sid(), version=VERSION, issue_instant=instant())
733+
response.issuer = _issuer
734+
response.in_response_to = in_response_to
735+
response.status = status
737736

738737
if consumer_url:
739738
response.destination = consumer_url

src/saml2/sigver.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1878,23 +1878,6 @@ def pre_encrypt_assertion(response):
18781878
return response
18791879

18801880

1881-
def response_factory(sign=False, encrypt=False, sign_alg=None, digest_alg=None,
1882-
**kwargs):
1883-
response = samlp.Response(id=sid(), version=VERSION,
1884-
issue_instant=instant())
1885-
1886-
if sign:
1887-
response.signature = pre_signature_part(
1888-
kwargs['id'], sign_alg=sign_alg, digest_alg=digest_alg)
1889-
if encrypt:
1890-
pass
1891-
1892-
for key, val in kwargs.items():
1893-
setattr(response, key, val)
1894-
1895-
return response
1896-
1897-
18981881
if __name__ == '__main__':
18991882
import argparse
19001883

tests/test_50_server.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,15 @@
2323
from saml2 import s_utils
2424
from saml2 import sigver
2525
from saml2 import time_util
26+
from saml2 import VERSION
2627
from saml2.s_utils import OtherError
2728
from saml2.s_utils import do_attribute_statement
2829
from saml2.s_utils import factory
30+
from saml2.s_utils import sid
2931
from saml2.soap import make_soap_enveloped_saml_thingy
3032
from saml2 import BINDING_HTTP_POST
3133
from saml2 import BINDING_HTTP_REDIRECT
34+
from saml2.time_util import instant
3235

3336
from pytest import raises
3437
from pathutils import full_path
@@ -44,6 +47,14 @@
4447
}
4548

4649

50+
def response_factory(**kwargs):
51+
response = samlp.Response(id=sid(), version=VERSION, issue_instant=instant())
52+
53+
for key, val in kwargs.items():
54+
setattr(response, key, val)
55+
56+
return response
57+
4758
def _eq(l1, l2):
4859
return set(l1) == set(l2)
4960

@@ -179,7 +190,7 @@ def test_assertion(self):
179190
assert subject.name_id.format == saml.NAMEID_FORMAT_TRANSIENT
180191

181192
def test_response(self):
182-
response = sigver.response_factory(
193+
response = response_factory(
183194
in_response_to="_012345",
184195
destination="https:#www.example.com",
185196
status=s_utils.success_status_factory(),
@@ -1239,7 +1250,7 @@ def test_assertion(self):
12391250
assert subject.name_id.format == saml.NAMEID_FORMAT_TRANSIENT
12401251

12411252
def test_response(self):
1242-
response = sigver.response_factory(
1253+
response = response_factory(
12431254
in_response_to="_012345",
12441255
destination="https:#www.example.com",
12451256
status=s_utils.success_status_factory(),

tests/test_51_client.py

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from saml2 import samlp
2222
from saml2 import sigver
2323
from saml2 import s_utils
24+
from saml2 import VERSION
2425
from saml2.assertion import Assertion
2526
from saml2.extension.requested_attributes import RequestedAttributes
2627
from saml2.extension.requested_attributes import RequestedAttribute
@@ -40,7 +41,10 @@
4041
from saml2.sigver import SignatureError, SigverError
4142
from saml2.s_utils import do_attribute_statement
4243
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
4448

4549
from defusedxml.common import EntitiesForbidden
4650

@@ -53,6 +57,14 @@
5357
"authn_auth": "http://www.example.com/login"
5458
}
5559

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+
5668
def generate_cert():
5769
sn = uuid.uuid4().urn
5870
cert_info = {
@@ -943,18 +955,19 @@ def test_sign_then_encrypt_assertion(self):
943955
# Create an Assertion instance from the signed assertion
944956
_ass = saml.assertion_from_string(sigass)
945957

946-
response = sigver.response_factory(
958+
response = response_factory(
947959
in_response_to="_012345",
948960
destination="https:#www.example.com",
949961
status=s_utils.success_status_factory(),
950962
issuer=self.server._issuer(),
951963
assertion=_ass
952964
)
953965

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+
)
958971

959972
seresp = samlp.response_from_string(enctext)
960973

@@ -1023,7 +1036,7 @@ def test_sign_then_encrypt_assertion2(self):
10231036
node_id=assertion.id)
10241037

10251038
sigass = rm_xmltag(sigass)
1026-
response = sigver.response_factory(
1039+
response = response_factory(
10271040
in_response_to="_012345",
10281041
destination="http://lingon.catalogix.se:8087/",
10291042
status=s_utils.success_status_factory(),
@@ -1116,7 +1129,7 @@ def test_sign_then_encrypt_assertion_advice_1(self):
11161129
assertion.advice.encrypted_assertion[0].add_extension_element(
11171130
a_assertion)
11181131

1119-
response = sigver.response_factory(
1132+
response = response_factory(
11201133
in_response_to="_012345",
11211134
destination="http://lingon.catalogix.se:8087/",
11221135
status=s_utils.success_status_factory(),
@@ -1267,7 +1280,7 @@ def test_sign_then_encrypt_assertion_advice_2(self):
12671280
assertion_2.signature = sigver.pre_signature_part(assertion_2.id,
12681281
_sec.my_cert, 1)
12691282

1270-
response = sigver.response_factory(
1283+
response = response_factory(
12711284
in_response_to="_012345",
12721285
destination="http://lingon.catalogix.se:8087/",
12731286
status=s_utils.success_status_factory(),
@@ -2560,7 +2573,7 @@ def test_sign_then_encrypt_assertion(self):
25602573
# Create an Assertion instance from the signed assertion
25612574
_ass = saml.assertion_from_string(sigass)
25622575

2563-
response = sigver.response_factory(
2576+
response = response_factory(
25642577
in_response_to="_012345",
25652578
destination="https:#www.example.com",
25662579
status=s_utils.success_status_factory(),
@@ -2640,7 +2653,7 @@ def test_sign_then_encrypt_assertion2(self):
26402653
node_id=assertion.id)
26412654

26422655
sigass = rm_xmltag(sigass)
2643-
response = sigver.response_factory(
2656+
response = response_factory(
26442657
in_response_to="_012345",
26452658
destination="http://lingon.catalogix.se:8087/",
26462659
status=s_utils.success_status_factory(),
@@ -2733,7 +2746,7 @@ def test_sign_then_encrypt_assertion_advice_1(self):
27332746
assertion.advice.encrypted_assertion[0].add_extension_element(
27342747
a_assertion)
27352748

2736-
response = sigver.response_factory(
2749+
response = response_factory(
27372750
in_response_to="_012345",
27382751
destination="http://lingon.catalogix.se:8087/",
27392752
status=s_utils.success_status_factory(),
@@ -2885,7 +2898,7 @@ def test_sign_then_encrypt_assertion_advice_2(self):
28852898
assertion_2.signature = sigver.pre_signature_part(assertion_2.id,
28862899
_sec.my_cert, 1)
28872900

2888-
response = sigver.response_factory(
2901+
response = response_factory(
28892902
in_response_to="_012345",
28902903
destination="http://lingon.catalogix.se:8087/",
28912904
status=s_utils.success_status_factory(),

0 commit comments

Comments
 (0)