Skip to content

Commit c6cf3ed

Browse files
author
Roland Hedberg
committed
Test of handling of unknown attributes.
1 parent 1553bc6 commit c6cf3ed

File tree

1 file changed

+36
-23
lines changed

1 file changed

+36
-23
lines changed

tests/test_19_attribute_converter.py

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
from attribute_statement_data import *
66

77
from pathutils import full_path
8-
from saml2.attribute_converter import AttributeConverterNOOP, to_local
8+
from saml2.attribute_converter import AttributeConverterNOOP
9+
from saml2.attribute_converter import to_local
910

1011

1112
def _eq(l1,l2):
@@ -58,11 +59,8 @@ def test_ava_fro_2(self):
5859
ava.update(ac.fro(ats))
5960

6061
print ava.keys()
61-
assert _eq(ava.keys(),['uid', 'swissedupersonuniqueid',
62-
'swissedupersonhomeorganizationtype',
63-
'eduPersonEntitlement', 'eduPersonAffiliation',
64-
'sn', 'mail', 'swissedupersonhomeorganization',
65-
'givenName'])
62+
assert _eq(ava.keys(), ['eduPersonEntitlement', 'eduPersonAffiliation',
63+
'uid', 'mail', 'givenName', 'sn'])
6664

6765
def test_to_attrstat_1(self):
6866
ava = { "givenName": "Roland", "sn": "Hedberg" }
@@ -131,22 +129,22 @@ def test_to_local_name(self):
131129

132130
assert _eq(lan, ['sn', 'givenName', 'title'])
133131

134-
def test_ava_fro_1(self):
135-
136-
attr = [saml.Attribute(friendly_name="surName",
137-
name="urn:oid:2.5.4.4",
138-
name_format="urn:oasis:names:tc:SAML:2.0:attrname-format:uri"),
139-
saml.Attribute(friendly_name="efternamn",
140-
name="urn:oid:2.5.4.42",
141-
name_format="urn:oasis:names:tc:SAML:2.0:attrname-format:uri"),
142-
saml.Attribute(friendly_name="titel",
143-
name="urn:oid:2.5.4.12",
144-
name_format="urn:oasis:names:tc:SAML:2.0:attrname-format:uri")]
145-
146-
result = attribute_converter.ava_fro(self.acs, attr)
147-
148-
print result
149-
assert result == {'givenName': [], 'sn': [], 'title': []}
132+
# def test_ava_fro_1(self):
133+
#
134+
# attr = [saml.Attribute(friendly_name="surName",
135+
# name="urn:oid:2.5.4.4",
136+
# name_format="urn:oasis:names:tc:SAML:2.0:attrname-format:uri"),
137+
# saml.Attribute(friendly_name="efternamn",
138+
# name="urn:oid:2.5.4.42",
139+
# name_format="urn:oasis:names:tc:SAML:2.0:attrname-format:uri"),
140+
# saml.Attribute(friendly_name="titel",
141+
# name="urn:oid:2.5.4.12",
142+
# name_format="urn:oasis:names:tc:SAML:2.0:attrname-format:uri")]
143+
#
144+
# result = attribute_converter.ava_fro(self.acs, attr)
145+
#
146+
# print result
147+
# assert result == {'givenName': [], 'sn': [], 'title': []}
150148

151149
def test_to_local_name_from_basic(self):
152150
attr = [saml.Attribute(
@@ -172,6 +170,21 @@ def test_unspecified_name_format(self):
172170
ava = to_local(self.acs, ats)
173171
assert ava == {'user_id': ['bob'], 'NameID': ['bobsnameagain']}
174172

173+
def test_mixed_attributes_1(self):
174+
ats = saml.attribute_statement_from_string(STATEMENT_MIXED)
175+
ava = to_local(self.acs, ats)
176+
assert ava == {'eduPersonAffiliation': ['staff'],
177+
'givenName': ['Roland'], 'sn': ['Hedberg'],
178+
'uid': ['demouser'], 'user_id': ['bob']}
179+
180+
# Allow unknown
181+
ava = to_local(self.acs, ats, True)
182+
assert ava == {'eduPersonAffiliation': ['staff'],
183+
'givenName': ['Roland'], 'sn': ['Hedberg'],
184+
'swissEduPersonHomeOrganizationType': ['others'],
185+
'uid': ['demouser'], 'urn:example:com:foo': ['Thing'],
186+
'user_id': ['bob']}
187+
175188

176189
def test_noop_attribute_conversion():
177190
ava = {"urn:oid:2.5.4.4": "Roland", "urn:oid:2.5.4.42": "Hedberg" }
@@ -193,5 +206,5 @@ def test_noop_attribute_conversion():
193206
if __name__ == "__main__":
194207
t = TestAC()
195208
t.setup_class()
196-
t.test_ava_fro_2()
209+
t.test_mixed_attributes_1()
197210
#test_noop_attribute_conversion()

0 commit comments

Comments
 (0)