Skip to content

Commit 2df04d0

Browse files
committed
Fix handling of static CO attribute values
SATOSA internal attribute values are of type list because some attributes can have multiple values.
1 parent dedf9fd commit 2df04d0

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/satosa/frontends/saml2.py

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

1819
from saml2 import SAMLError, xmldsig
1920
from saml2.config import IdPConfig
@@ -742,7 +743,12 @@ def _handle_authn_response(self, context, internal_response):
742743
if self.KEY_CO_ATTRIBUTES in co_config:
743744
attributes = internal_response.attributes
744745
for attribute, value in co_config[self.KEY_CO_ATTRIBUTES].items():
745-
attributes[attribute] = value
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+
)
746752

747753
# Handle the authentication response.
748754
return super()._handle_authn_response(context, internal_response, idp)

tests/satosa/frontends/test_saml2.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -413,9 +413,9 @@ class TestSAMLVirtualCoFrontend(TestSAMLFrontend):
413413
CO_CO = "friendlycountryname"
414414
CO_NOREDUORGACRONYM = "noreduorgacronym"
415415
CO_STATIC_SAML_ATTRIBUTES = {
416-
CO_O: "Medium Energy Synchrotron Source",
417-
CO_C: "US",
418-
CO_CO: "United States",
416+
CO_O: ["Medium Energy Synchrotron Source"],
417+
CO_C: ["US"],
418+
CO_CO: ["United States"],
419419
CO_NOREDUORGACRONYM: ["MESS"]
420420
}
421421
KEY_SSO = "single_sign_on_service"

0 commit comments

Comments
 (0)