Skip to content

Commit 149edd2

Browse files
committed
Better fix for handling of static CO attribute values.
SATOSA internal attribute values are of type list because some attributes can have multiple values. This fix works for Python 3.4 and above but should be refactored when Python 3.4 support is no longer required.
1 parent 2df04d0 commit 149edd2

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/satosa/frontends/saml2.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
from urllib.parse import unquote_plus
1515
from urllib.parse import urlparse
1616
from http.cookies import SimpleCookie
17-
from typing import Iterable
1817

1918
from saml2 import SAMLError, xmldsig
2019
from saml2.config import IdPConfig
@@ -743,12 +742,15 @@ def _handle_authn_response(self, context, internal_response):
743742
if self.KEY_CO_ATTRIBUTES in co_config:
744743
attributes = internal_response.attributes
745744
for attribute, value in co_config[self.KEY_CO_ATTRIBUTES].items():
746-
attributes[attribute] = (
747-
value # keep the value as is
748-
if isinstance(value, Iterable) # if it is already a list
749-
and not isinstance(value, str) # and not a string
750-
else [value] # otherwise wrap in a list
751-
)
745+
# This should be refactored when Python 3.4 support is
746+
# no longer required to use isinstance(value, Iterable).
747+
try:
748+
if iter(value) and not isinstance(value, str):
749+
attributes[attribute] = value
750+
else:
751+
attributes[attribute] = [value]
752+
except TypeError:
753+
attributes[attribute] = [value]
752754

753755
# Handle the authentication response.
754756
return super()._handle_authn_response(context, internal_response, idp)

0 commit comments

Comments
 (0)