summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRebecka Gulliksson <rebecka.gulliksson@umu.se>2016-09-27 09:24:06 +0200
committerRebecka Gulliksson <rebecka.gulliksson@umu.se>2016-09-27 15:15:55 +0200
commit1891faa374a413eab52903365ac197b5999e1f5f (patch)
treeb905071a3723ff4a143cfc4b8858f2ad9910b387
parent17e6883bd76d90f572430228d98d87dd3b0a216f (diff)
downloadpysaml2-1891faa374a413eab52903365ac197b5999e1f5f.tar.gz
Automagically nest eduPersonTargetedID in a NameID.
-rw-r--r--src/saml2/attribute_converter.py17
-rw-r--r--tests/test_19_attribute_converter.py11
2 files changed, 20 insertions, 8 deletions
diff --git a/src/saml2/attribute_converter.py b/src/saml2/attribute_converter.py
index 85ec26c8..20686e7e 100644
--- a/src/saml2/attribute_converter.py
+++ b/src/saml2/attribute_converter.py
@@ -11,7 +11,7 @@ from saml2.s_utils import do_ava
from saml2 import saml
from saml2 import extension_elements_to_elements
from saml2 import SAMLError
-from saml2.saml import NAME_FORMAT_UNSPECIFIED
+from saml2.saml import NAME_FORMAT_UNSPECIFIED, NAMEID_FORMAT_PERSISTENT, NameID
import logging
logger = logging.getLogger(__name__)
@@ -488,14 +488,19 @@ class AttributeConverter(object):
"""
attributes = []
for key, value in attrvals.items():
- lkey = key.lower()
- try:
+ name = self._to.get(key.lower())
+ if name:
+ if name == "urn:oid:1.3.6.1.4.1.5923.1.1.1.10":
+ # special case for eduPersonTargetedID
+ attr_value = do_ava(NameID(format=NAMEID_FORMAT_PERSISTENT, text=value).to_string())
+ else:
+ attr_value = do_ava(value)
attributes.append(factory(saml.Attribute,
- name=self._to[lkey],
+ name=name,
name_format=self.name_format,
friendly_name=key,
- attribute_value=do_ava(value)))
- except KeyError:
+ attribute_value=attr_value))
+ else:
attributes.append(factory(saml.Attribute,
name=key,
attribute_value=do_ava(value)))
diff --git a/tests/test_19_attribute_converter.py b/tests/test_19_attribute_converter.py
index 01960f6c..7c1951e4 100644
--- a/tests/test_19_attribute_converter.py
+++ b/tests/test_19_attribute_converter.py
@@ -5,10 +5,10 @@ from saml2 import attribute_converter, saml
from attribute_statement_data import *
from pathutils import full_path
-from saml2.attribute_converter import AttributeConverterNOOP
+from saml2.attribute_converter import AttributeConverterNOOP, from_local
from saml2.attribute_converter import AttributeConverter
from saml2.attribute_converter import to_local
-from saml2.saml import attribute_from_string
+from saml2.saml import attribute_from_string, name_id_from_string, NameID, NAMEID_FORMAT_PERSISTENT
from saml2.saml import attribute_statement_from_string
@@ -210,6 +210,13 @@ class TestAC():
attr_conv.adjust()
assert attr_conv._fro is None and attr_conv._to is None
+ def test_from_local_nest_eduPersonTargetedID_in_NameID(self):
+ ava = {"edupersontargetedid": "test value"}
+ attributes = from_local(self.acs, ava, URI_NF)
+ assert len(attributes) == 1
+ assert len(attributes[0].attribute_value) == 1
+ assert attributes[0].attribute_value[0].text == NameID(format=NAMEID_FORMAT_PERSISTENT, text="test value").to_string().decode("utf-8")
+
def test_noop_attribute_conversion():
ava = {"urn:oid:2.5.4.4": "Roland", "urn:oid:2.5.4.42": "Hedberg"}