Skip to content

Commit fbb0b5a

Browse files
committed
Fix Name-ID caching type inconsistency
If we already promoted (in #0515de9f) the saml2.cache.Cache to be a bit smart when it comes to understanding the data it stores - that is decoding name_id in the get() method, let's be consistent and do the reverse operation directly in the set() method. This also fixes the issue with djangosaml2 that PR #321 tried to solve (but ugly way).
1 parent 5388f01 commit fbb0b5a

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

src/saml2/cache.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ def set(self, name_id, entity_id, info, not_on_or_after=0):
113113
:param info: The session info, the assertion is part of this
114114
:param not_on_or_after: A time after which the assertion is not valid.
115115
"""
116+
info = dict(info)
117+
if 'name_id' in info and not isinstance(info['name_id'], six.string_types):
118+
# make friendly to (JSON) serialization
119+
info['name_id'] = code(name_id)
120+
116121
cni = code(name_id)
117122
if cni not in self._db:
118123
self._db[cni] = {}

src/saml2/population.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,11 @@ def add_information_about_person(self, session_info):
2020
"""If there already are information from this source in the cache
2121
this function will overwrite that information"""
2222

23+
session_info = dict(session_info)
2324
name_id = session_info["name_id"]
24-
# make friendly to (JSON) serialization
25-
#session_info['name_id'] = code(name_id)
26-
name_id_coded = code(name_id)
27-
issuer = session_info["issuer"]
28-
del session_info["issuer"]
25+
issuer = session_info.pop("issuer")
2926
self.cache.set(name_id, issuer, session_info,
3027
session_info["not_on_or_after"])
31-
session_info['name_id'] = name_id_coded
3228
return name_id
3329

3430
def stale_sources_for_person(self, name_id, sources=None):

0 commit comments

Comments
 (0)