Skip to content

Commit a9983d5

Browse files
author
Serge Domkowski
committed
Allow logout to succeed if NotOnOrAfter expired.
1 parent 6c0bec3 commit a9983d5

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

src/saml2/client.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,9 @@ def do_logout(self, name_id, entity_ids, reason, expire, sign=None,
207207
destination = destinations(srvs)[0]
208208
logger.info("destination to provider: %s", destination)
209209
try:
210-
session_info = self.users.get_info_from(name_id, entity_id)
210+
session_info = self.users.get_info_from(name_id,
211+
entity_id,
212+
False)
211213
session_indexes = [session_info['session_index']]
212214
except KeyError:
213215
session_indexes = None

src/saml2/population.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ def issuers_of_info(self, name_id):
4545
def get_identity(self, name_id, entities=None, check_not_on_or_after=True):
4646
return self.cache.get_identity(name_id, entities, check_not_on_or_after)
4747

48-
def get_info_from(self, name_id, entity_id):
49-
return self.cache.get(name_id, entity_id)
48+
def get_info_from(self, name_id, entity_id, check_not_on_or_after=True):
49+
return self.cache.get(name_id, entity_id, check_not_on_or_after)
5050

5151
def subjects(self):
5252
"""Returns the name id's for all the persons in the cache"""

tests/test_51_client.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
from saml2.sigver import verify_redirect_signature
3333
from saml2.s_utils import do_attribute_statement
3434
from saml2.s_utils import factory
35-
from saml2.time_util import in_a_while
35+
from saml2.time_util import in_a_while, a_while_ago
3636

3737
from fakeIDP import FakeIDP
3838
from fakeIDP import unpack_form
@@ -1265,6 +1265,36 @@ def test_do_logout_post(self):
12651265
BINDING_HTTP_POST)
12661266
assert b'<ns0:SessionIndex>_foo</ns0:SessionIndex>' in res.xmlstr
12671267

1268+
def test_do_logout_session_expired(self):
1269+
# information about the user from an IdP
1270+
session_info = {
1271+
"name_id": nid,
1272+
"issuer": "urn:mace:example.com:saml:roland:idp",
1273+
"not_on_or_after": a_while_ago(minutes=15),
1274+
"ava": {
1275+
"givenName": "Anders",
1276+
"surName": "Andersson",
1277+
1278+
},
1279+
"session_index": SessionIndex("_foo")
1280+
}
1281+
self.client.users.add_information_about_person(session_info)
1282+
entity_ids = self.client.users.issuers_of_info(nid)
1283+
assert entity_ids == ["urn:mace:example.com:saml:roland:idp"]
1284+
resp = self.client.do_logout(nid, entity_ids, "Tired",
1285+
in_a_while(minutes=5), sign=True,
1286+
expected_binding=BINDING_HTTP_POST)
1287+
assert resp
1288+
assert len(resp) == 1
1289+
assert list(resp.keys()) == entity_ids
1290+
binding, info = resp[entity_ids[0]]
1291+
assert binding == BINDING_HTTP_POST
1292+
1293+
_dic = unpack_form(info["data"][3])
1294+
res = self.server.parse_logout_request(_dic["SAMLRequest"],
1295+
BINDING_HTTP_POST)
1296+
assert b'<ns0:SessionIndex>_foo</ns0:SessionIndex>' in res.xmlstr
1297+
12681298

12691299
# Below can only be done with dummy Server
12701300
IDP = "urn:mace:example.com:saml:roland:idp"

0 commit comments

Comments
 (0)