Skip to content

Commit c63f108

Browse files
Merge pull request #801 from ErwinJunge/response-issuer-none
Issuer in a Response is optional
2 parents 71b53cf + e393022 commit c63f108

File tree

2 files changed

+61
-28
lines changed

2 files changed

+61
-28
lines changed

src/saml2/response.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,12 @@ def update(self, mold):
435435
self.response = mold.response
436436

437437
def issuer(self):
438-
return self.response.issuer.text.strip()
438+
issuer_value = (
439+
self.response.issuer.text
440+
if self.response.issuer is not None
441+
else ""
442+
).strip()
443+
return issuer_value
439444

440445

441446
class LogoutResponse(StatusResponse):
@@ -1116,7 +1121,7 @@ def session_info(self):
11161121
raise StatusInvalidAuthnResponseStatement(
11171122
"The Authn Response Statement is not valid"
11181123
)
1119-
1124+
11201125
def __str__(self):
11211126
return self.xmlstr
11221127

tests/test_41_response.py

Lines changed: 54 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -48,56 +48,84 @@ def setup_class(self):
4848

4949
self._resp_ = server.create_authn_response(
5050
IDENTITY,
51-
"id12", # in_response_to
52-
"http://lingon.catalogix.se:8087/",
53-
# consumer_url
54-
"urn:mace:example.com:saml:roland:sp",
55-
# sp_entity_id
56-
name_id=name_id)
51+
in_response_to="id12",
52+
destination="http://lingon.catalogix.se:8087/",
53+
sp_entity_id="urn:mace:example.com:saml:roland:sp",
54+
name_id=name_id,
55+
)
5756

5857
self._sign_resp_ = server.create_authn_response(
5958
IDENTITY,
60-
"id12", # in_response_to
61-
"http://lingon.catalogix.se:8087/", # consumer_url
62-
"urn:mace:example.com:saml:roland:sp", # sp_entity_id
59+
in_response_to="id12",
60+
destination="http://lingon.catalogix.se:8087/",
61+
sp_entity_id="urn:mace:example.com:saml:roland:sp",
6362
name_id=name_id,
64-
sign_assertion=True)
63+
sign_assertion=True,
64+
)
6565

6666
self._resp_authn = server.create_authn_response(
6767
IDENTITY,
68-
"id12", # in_response_to
69-
"http://lingon.catalogix.se:8087/", # consumer_url
70-
"urn:mace:example.com:saml:roland:sp", # sp_entity_id
68+
in_response_to="id12",
69+
destination="http://lingon.catalogix.se:8087/",
70+
sp_entity_id="urn:mace:example.com:saml:roland:sp",
71+
name_id=name_id,
72+
authn=AUTHN,
73+
)
74+
75+
self._resp_issuer_none = server.create_authn_response(
76+
IDENTITY,
77+
in_response_to="id12",
78+
destination="http://lingon.catalogix.se:8087/",
79+
sp_entity_id="urn:mace:example.com:saml:roland:sp",
7180
name_id=name_id,
72-
authn=AUTHN)
81+
)
82+
self._resp_issuer_none.issuer = None
7383

7484
conf = config.SPConfig()
7585
conf.load_file("server_conf")
7686
self.conf = conf
7787

7888
def test_1(self):
7989
xml_response = ("%s" % (self._resp_,))
80-
resp = response_factory(xml_response, self.conf,
81-
return_addrs=[
82-
"http://lingon.catalogix.se:8087/"],
83-
outstanding_queries={
84-
"id12": "http://localhost:8088/sso"},
85-
timeslack=TIMESLACK, decode=False)
90+
resp = response_factory(
91+
xml_response, self.conf,
92+
return_addrs=["http://lingon.catalogix.se:8087/"],
93+
outstanding_queries={"id12": "http://localhost:8088/sso"},
94+
timeslack=TIMESLACK,
95+
decode=False,
96+
)
8697

8798
assert isinstance(resp, StatusResponse)
8899
assert isinstance(resp, AuthnResponse)
89100

90101
def test_2(self):
91102
xml_response = self._sign_resp_
92-
resp = response_factory(xml_response, self.conf,
93-
return_addrs=[
94-
"http://lingon.catalogix.se:8087/"],
95-
outstanding_queries={
96-
"id12": "http://localhost:8088/sso"},
97-
timeslack=TIMESLACK, decode=False)
103+
resp = response_factory(
104+
xml_response,
105+
self.conf,
106+
return_addrs=["http://lingon.catalogix.se:8087/"],
107+
outstanding_queries={"id12": "http://localhost:8088/sso"},
108+
timeslack=TIMESLACK,
109+
decode=False,
110+
)
111+
112+
assert isinstance(resp, StatusResponse)
113+
assert isinstance(resp, AuthnResponse)
114+
115+
def test_issuer_none(self):
116+
xml_response = ("%s" % (self._resp_issuer_none,))
117+
resp = response_factory(
118+
xml_response,
119+
self.conf,
120+
return_addrs=["http://lingon.catalogix.se:8087/"],
121+
outstanding_queries={"id12": "http://localhost:8088/sso"},
122+
timeslack=TIMESLACK,
123+
decode=False,
124+
)
98125

99126
assert isinstance(resp, StatusResponse)
100127
assert isinstance(resp, AuthnResponse)
128+
assert resp.issuer() == ""
101129

102130
@mock.patch('saml2.time_util.datetime')
103131
def test_false_sign(self, mock_datetime):

0 commit comments

Comments
 (0)