Skip to content

Commit d835252

Browse files
committed
Handle KeyError when retrieving SessionIndex
This was broken in commit b69e925 Fixes #826
1 parent f0a6d63 commit d835252

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

src/saml2/client.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,9 +294,12 @@ def do_logout(
294294
)
295295
continue
296296

297-
session_info = self.users.get_info_from(name_id, entity_id, False)
298-
session_index = session_info.get('session_index')
299-
session_indexes = [session_index] if session_index else None
297+
try:
298+
session_info = self.users.get_info_from(name_id, entity_id, False)
299+
session_index = session_info.get('session_index')
300+
session_indexes = [session_index] if session_index else None
301+
except KeyError:
302+
session_indexes = None
300303

301304
sign = sign if sign is not None else self.logout_requests_signed
302305
sign_post = sign and (

tests/test_51_client.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1594,6 +1594,30 @@ def test_do_logout_post(self):
15941594
BINDING_HTTP_POST)
15951595
assert b'<ns0:SessionIndex>_foo</ns0:SessionIndex>' in res.xmlstr
15961596

1597+
def test_do_logout_redirect_no_cache(self):
1598+
conf = config.SPConfig()
1599+
conf.load_file("sp_slo_redirect_conf")
1600+
client = Saml2Client(conf)
1601+
1602+
entity_ids = ["urn:mace:example.com:saml:roland:idp"]
1603+
resp = client.do_logout(nid, entity_ids, "urn:oasis:names:tc:SAML:2.0:logout:user",
1604+
in_a_while(minutes=5),
1605+
expected_binding=BINDING_HTTP_REDIRECT)
1606+
assert resp
1607+
assert len(resp) == 1
1608+
assert list(resp.keys()) == entity_ids
1609+
binding, info = resp[entity_ids[0]]
1610+
assert binding == BINDING_HTTP_REDIRECT
1611+
1612+
loc = info["headers"][0][1]
1613+
_, _, _, _, qs, _ = parse.urlparse(loc)
1614+
qs = parse.parse_qs(qs)
1615+
assert _leq(qs.keys(), ['SAMLRequest', 'RelayState'])
1616+
1617+
res = self.server.parse_logout_request(qs["SAMLRequest"][0],
1618+
BINDING_HTTP_REDIRECT)
1619+
assert res.subject_id() == nid
1620+
15971621
def test_do_logout_session_expired(self):
15981622
# information about the user from an IdP
15991623
session_info = {

0 commit comments

Comments
 (0)