Merge pull request #359 from rebeckag/nest-eptid

Automagically nest eduPersonTargetedID in a NameID.
This commit is contained in:
Roland Hedberg
2016-09-29 08:24:17 -04:00
committed by GitHub
2 changed files with 20 additions and 8 deletions

View File

@@ -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__)
@@ -491,14 +491,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)))

View File

@@ -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"}