|
10 | 10 | from saml2.attribute_converter import to_local
|
11 | 11 | from saml2.saml import attribute_from_string, name_id_from_string, NameID, NAMEID_FORMAT_PERSISTENT
|
12 | 12 | from saml2.saml import attribute_statement_from_string
|
| 13 | +import saml2.attributemaps.saml_uri as saml_map |
13 | 14 |
|
14 | 15 |
|
15 | 16 | def _eq(l1, l2):
|
@@ -139,12 +140,14 @@ def test_to_local_name(self):
|
139 | 140 | def test_to_local_name_from_unspecified(self):
|
140 | 141 | _xml = """<?xml version='1.0' encoding='UTF-8'?>
|
141 | 142 | <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 | + """ |
148 | 151 |
|
149 | 152 | attr = attribute_statement_from_string(_xml)
|
150 | 153 | ava = attribute_converter.to_local(self.acs, attr)
|
@@ -236,26 +239,70 @@ def test_noop_attribute_conversion():
|
236 | 239 | assert attr.attribute_value[0].text == "Roland"
|
237 | 240 |
|
238 | 241 |
|
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" |
248 | 281 |
|
| 282 | + assert failures != len(acs) |
249 | 283 |
|
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) |
259 | 306 |
|
260 | 307 |
|
261 | 308 | if __name__ == "__main__":
|
|
0 commit comments