Skip to content

Commit 701bdac

Browse files
author
ivan
committed
Add eIDAS namespace and attributes
1 parent 2326962 commit 701bdac

File tree

2 files changed

+88
-24
lines changed

2 files changed

+88
-24
lines changed

src/saml2/attributemaps/saml_uri.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,19 @@
1313
SIS = 'urn:oid:1.2.752.194.10.2.'
1414
UMICH = 'urn:oid:1.3.6.1.4.1.250.1.57.'
1515
OPENOSI_OID = 'urn:oid:1.3.6.1.4.1.27630.2.1.1.' #openosi-0.82.schema http://www.openosi.org/osi/display/ldap/Home
16+
EIDAS_NATURALPERSON = 'http://eidas.europa.eu/attributes/naturalperson/'
1617

1718
MAP = {
1819
'identifier': 'urn:oasis:names:tc:SAML:2.0:attrname-format:uri',
1920
'fro': {
21+
EIDAS_NATURALPERSON+'PersonIdentifier': 'PersonIdentifier',
22+
EIDAS_NATURALPERSON+'FamilyName': 'FamilyName',
23+
EIDAS_NATURALPERSON+'FirstName': 'FirstName',
24+
EIDAS_NATURALPERSON+'DateOfBirth': 'DateOfBirth',
25+
EIDAS_NATURALPERSON+'BirthName': 'BirthName',
26+
EIDAS_NATURALPERSON+'PlaceOfBirth': 'PlaceOfBirth',
27+
EIDAS_NATURALPERSON+'CurrentAddress': 'CurrentAddress',
28+
EIDAS_NATURALPERSON+'Gender': 'Gender',
2029
EDUCOURSE_OID+'1': 'eduCourseOffering',
2130
EDUCOURSE_OID+'2': 'eduCourseMember',
2231
EDUMEMBER1_OID+'1': 'isMemberOf',
@@ -161,6 +170,14 @@
161170
X500ATTR_OID+'65': 'pseudonym',
162171
},
163172
'to': {
173+
'PersonIdentifier': EIDAS_NATURALPERSON+'PersonIdentifier',
174+
'FamilyName': EIDAS_NATURALPERSON+'FamilyName',
175+
'FirstName': EIDAS_NATURALPERSON+'FirstName',
176+
'DateOfBirth': EIDAS_NATURALPERSON+'DateOfBirth',
177+
'BirthName': EIDAS_NATURALPERSON+'BirthName',
178+
'PlaceOfBirth': EIDAS_NATURALPERSON+'PlaceOfBirth',
179+
'CurrentAddress': EIDAS_NATURALPERSON+'CurrentAddress',
180+
'Gender': EIDAS_NATURALPERSON+'Gender',
164181
'associatedDomain': UCL_DIR_PILOT+'37',
165182
'authorityRevocationList': X500ATTR_OID+'38',
166183
'businessCategory': X500ATTR_OID+'15',

tests/test_19_attribute_converter.py

Lines changed: 71 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from saml2.attribute_converter import to_local
1111
from saml2.saml import attribute_from_string, name_id_from_string, NameID, NAMEID_FORMAT_PERSISTENT
1212
from saml2.saml import attribute_statement_from_string
13+
import saml2.attributemaps.saml_uri as saml_map
1314

1415

1516
def _eq(l1, l2):
@@ -139,12 +140,14 @@ def test_to_local_name(self):
139140
def test_to_local_name_from_unspecified(self):
140141
_xml = """<?xml version='1.0' encoding='UTF-8'?>
141142
<ns0:AttributeStatement xmlns:ns0="urn:oasis:names:tc:SAML:2.0:assertion">
142-
<ns0:Attribute
143-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
144-
Name="EmailAddress"
145-
NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:unspecified">
146-
<ns0:AttributeValue xsi:type="xs:string">[email protected]</ns0:AttributeValue>
147-
</ns0:Attribute></ns0:AttributeStatement>"""
143+
<ns0:Attribute
144+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
145+
Name="EmailAddress"
146+
NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:unspecified">
147+
<ns0:AttributeValue xsi:type="xs:string">[email protected]</ns0:AttributeValue>
148+
</ns0:Attribute>
149+
</ns0:AttributeStatement>
150+
"""
148151

149152
attr = attribute_statement_from_string(_xml)
150153
ava = attribute_converter.to_local(self.acs, attr)
@@ -236,26 +239,70 @@ def test_noop_attribute_conversion():
236239
assert attr.attribute_value[0].text == "Roland"
237240

238241

239-
ava = """<?xml version='1.0' encoding='UTF-8'?>
240-
<ns0:Attribute xmlns:ns0="urn:oasis:names:tc:SAML:2.0:assertion"
241-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
242-
FriendlyName="schacHomeOrganization" Name="urn:oid:1.3.6.1.4.1.25178.1.2.9"
243-
NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri">
244-
<ns0:AttributeValue xsi:nil="true" xsi:type="xs:string">
245-
uu.se
246-
</ns0:AttributeValue>
247-
</ns0:Attribute>"""
242+
class BuilderAVA():
243+
def __init__(self, name, friendly_name, name_format):
244+
template = """<?xml version='1.0' encoding='UTF-8'?>
245+
<ns0:Attribute xmlns:ns0="urn:oasis:names:tc:SAML:2.0:assertion"
246+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
247+
Name="{attr_name}"
248+
FriendlyName="{attr_friendly_name}"
249+
NameFormat="{attr_name_format}">
250+
<ns0:AttributeValue xsi:nil="true" xsi:type="xs:string">
251+
uu.se
252+
</ns0:AttributeValue>
253+
</ns0:Attribute>
254+
"""
255+
256+
self.ava = template.format(
257+
attr_name=name,
258+
attr_friendly_name=friendly_name,
259+
attr_name_format=name_format)
260+
261+
262+
class TestSchac():
263+
def test(self):
264+
failures = 0
265+
friendly_name = "schacHomeOrganization"
266+
ava_schac = BuilderAVA(
267+
"urn:oid:1.3.6.1.4.1.25178.1.2.9",
268+
friendly_name,
269+
saml_map.MAP['identifier'])
270+
271+
attr = attribute_from_string(ava_schac.ava)
272+
acs = attribute_converter.ac_factory()
273+
274+
for ac in acs:
275+
try:
276+
res = ac.ava_from(attr)
277+
except KeyError:
278+
failures += 1
279+
else:
280+
assert res[0] == "schacHomeOrganization"
248281

282+
assert failures != len(acs)
249283

250-
def test_schac():
251-
attr = attribute_from_string(ava)
252-
acs = attribute_converter.ac_factory()
253-
for ac in acs:
254-
try:
255-
res = ac.ava_from(attr)
256-
assert res[0] == "schacHomeOrganization"
257-
except KeyError:
258-
pass
284+
285+
class TestEIDAS():
286+
def test(self):
287+
failures = 0
288+
friendly_name = 'PersonIdentifier'
289+
ava_eidas = BuilderAVA(
290+
saml_map.EIDAS_NATURALPERSON + friendly_name,
291+
friendly_name,
292+
saml_map.MAP['identifier'])
293+
294+
attr = attribute_from_string(ava_eidas.ava)
295+
acs = attribute_converter.ac_factory()
296+
297+
for ac in acs:
298+
try:
299+
res = ac.ava_from(attr)
300+
except KeyError:
301+
failures += 1
302+
else:
303+
assert res[0] == friendly_name
304+
305+
assert failures != len(acs)
259306

260307

261308
if __name__ == "__main__":

0 commit comments

Comments
 (0)