Skip to content

Commit

Permalink
Merge pull request #801 from ErwinJunge/response-issuer-none
Browse files Browse the repository at this point in the history
Issuer in a Response is optional
  • Loading branch information
c00kiemon5ter authored May 17, 2021
2 parents 71b53cf + e393022 commit c63f108
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 28 deletions.
9 changes: 7 additions & 2 deletions src/saml2/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,12 @@ def update(self, mold):
self.response = mold.response

def issuer(self):
return self.response.issuer.text.strip()
issuer_value = (
self.response.issuer.text
if self.response.issuer is not None
else ""
).strip()
return issuer_value


class LogoutResponse(StatusResponse):
Expand Down Expand Up @@ -1116,7 +1121,7 @@ def session_info(self):
raise StatusInvalidAuthnResponseStatement(
"The Authn Response Statement is not valid"
)

def __str__(self):
return self.xmlstr

Expand Down
80 changes: 54 additions & 26 deletions tests/test_41_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,56 +48,84 @@ def setup_class(self):

self._resp_ = server.create_authn_response(
IDENTITY,
"id12", # in_response_to
"http://lingon.catalogix.se:8087/",
# consumer_url
"urn:mace:example.com:saml:roland:sp",
# sp_entity_id
name_id=name_id)
in_response_to="id12",
destination="http://lingon.catalogix.se:8087/",
sp_entity_id="urn:mace:example.com:saml:roland:sp",
name_id=name_id,
)

self._sign_resp_ = server.create_authn_response(
IDENTITY,
"id12", # in_response_to
"http://lingon.catalogix.se:8087/", # consumer_url
"urn:mace:example.com:saml:roland:sp", # sp_entity_id
in_response_to="id12",
destination="http://lingon.catalogix.se:8087/",
sp_entity_id="urn:mace:example.com:saml:roland:sp",
name_id=name_id,
sign_assertion=True)
sign_assertion=True,
)

self._resp_authn = server.create_authn_response(
IDENTITY,
"id12", # in_response_to
"http://lingon.catalogix.se:8087/", # consumer_url
"urn:mace:example.com:saml:roland:sp", # sp_entity_id
in_response_to="id12",
destination="http://lingon.catalogix.se:8087/",
sp_entity_id="urn:mace:example.com:saml:roland:sp",
name_id=name_id,
authn=AUTHN,
)

self._resp_issuer_none = server.create_authn_response(
IDENTITY,
in_response_to="id12",
destination="http://lingon.catalogix.se:8087/",
sp_entity_id="urn:mace:example.com:saml:roland:sp",
name_id=name_id,
authn=AUTHN)
)
self._resp_issuer_none.issuer = None

conf = config.SPConfig()
conf.load_file("server_conf")
self.conf = conf

def test_1(self):
xml_response = ("%s" % (self._resp_,))
resp = response_factory(xml_response, self.conf,
return_addrs=[
"http://lingon.catalogix.se:8087/"],
outstanding_queries={
"id12": "http://localhost:8088/sso"},
timeslack=TIMESLACK, decode=False)
resp = response_factory(
xml_response, self.conf,
return_addrs=["http://lingon.catalogix.se:8087/"],
outstanding_queries={"id12": "http://localhost:8088/sso"},
timeslack=TIMESLACK,
decode=False,
)

assert isinstance(resp, StatusResponse)
assert isinstance(resp, AuthnResponse)

def test_2(self):
xml_response = self._sign_resp_
resp = response_factory(xml_response, self.conf,
return_addrs=[
"http://lingon.catalogix.se:8087/"],
outstanding_queries={
"id12": "http://localhost:8088/sso"},
timeslack=TIMESLACK, decode=False)
resp = response_factory(
xml_response,
self.conf,
return_addrs=["http://lingon.catalogix.se:8087/"],
outstanding_queries={"id12": "http://localhost:8088/sso"},
timeslack=TIMESLACK,
decode=False,
)

assert isinstance(resp, StatusResponse)
assert isinstance(resp, AuthnResponse)

def test_issuer_none(self):
xml_response = ("%s" % (self._resp_issuer_none,))
resp = response_factory(
xml_response,
self.conf,
return_addrs=["http://lingon.catalogix.se:8087/"],
outstanding_queries={"id12": "http://localhost:8088/sso"},
timeslack=TIMESLACK,
decode=False,
)

assert isinstance(resp, StatusResponse)
assert isinstance(resp, AuthnResponse)
assert resp.issuer() == ""

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

0 comments on commit c63f108

Please sign in to comment.