@@ -285,28 +285,47 @@ def test_acr_mapping_per_idp_in_authn_response(self, context, idp_conf, sp_conf,
285
285
authn_context_class_ref = resp .assertion .authn_statement [0 ].authn_context .authn_context_class_ref
286
286
assert authn_context_class_ref .text == expected_loa
287
287
288
- @pytest .mark .parametrize ("entity_category, entity_category_module, expected_attributes" , [
289
- (["" ], "swamid" , swamid .RELEASE ["" ]),
290
- ([COCO ], "edugain" , edugain .RELEASE ["" ] + edugain .RELEASE [COCO ]),
291
- ([RESEARCH_AND_SCHOLARSHIP ], "refeds" , refeds .RELEASE ["" ] + refeds .RELEASE [RESEARCH_AND_SCHOLARSHIP ]),
292
- ([RESEARCH_AND_EDUCATION , EU ], "swamid" , swamid .RELEASE ["" ] + swamid .RELEASE [(RESEARCH_AND_EDUCATION , EU )]),
293
- ([RESEARCH_AND_EDUCATION , HEI ], "swamid" , swamid .RELEASE ["" ] + swamid .RELEASE [(RESEARCH_AND_EDUCATION , HEI )]),
294
- ([RESEARCH_AND_EDUCATION , NREN ], "swamid" , swamid .RELEASE ["" ] + swamid .RELEASE [(RESEARCH_AND_EDUCATION , NREN )]),
295
- ([SFS_1993_1153 ], "swamid" , swamid .RELEASE ["" ] + swamid .RELEASE [SFS_1993_1153 ]),
296
- ])
297
- def test_respect_sp_entity_categories (self , context , entity_category , entity_category_module , expected_attributes ,
298
- idp_conf , sp_conf , internal_response ):
288
+ @pytest .mark .parametrize (
289
+ "entity_category, entity_category_module, expected_attributes" ,
290
+ [
291
+ (["" ], "swamid" , swamid .RELEASE ["" ]),
292
+ ([COCO ], "edugain" , edugain .RELEASE ["" ] + edugain .RELEASE [COCO ]),
293
+ ([RESEARCH_AND_SCHOLARSHIP ], "refeds" , refeds .RELEASE ["" ] + refeds .RELEASE [RESEARCH_AND_SCHOLARSHIP ]),
294
+ ([RESEARCH_AND_EDUCATION , EU ], "swamid" , swamid .RELEASE ["" ] + swamid .RELEASE [(RESEARCH_AND_EDUCATION , EU )]),
295
+ ([RESEARCH_AND_EDUCATION , HEI ], "swamid" , swamid .RELEASE ["" ] + swamid .RELEASE [(RESEARCH_AND_EDUCATION , HEI )]),
296
+ ([RESEARCH_AND_EDUCATION , NREN ], "swamid" , swamid .RELEASE ["" ] + swamid .RELEASE [(RESEARCH_AND_EDUCATION , NREN )]),
297
+ ([SFS_1993_1153 ], "swamid" , swamid .RELEASE ["" ] + swamid .RELEASE [SFS_1993_1153 ]),
298
+ ]
299
+ )
300
+ def test_respect_sp_entity_categories (
301
+ self ,
302
+ context ,
303
+ entity_category ,
304
+ entity_category_module ,
305
+ expected_attributes ,
306
+ idp_conf ,
307
+ sp_conf ,
308
+ internal_response
309
+ ):
299
310
idp_metadata_str = create_metadata_from_config_dict (idp_conf )
300
311
idp_conf ["service" ]["idp" ]["policy" ]["default" ]["entity_categories" ] = [entity_category_module ]
301
312
if all (entity_category ): # don't insert empty entity category
302
313
sp_conf ["entity_category" ] = entity_category
303
314
if entity_category == [COCO ]:
304
315
sp_conf ["service" ]["sp" ]["required_attributes" ] = expected_attributes
305
316
306
- expected_attributes_in_all_entity_categories = list (
307
- itertools .chain (swamid .RELEASE ["" ], edugain .RELEASE [COCO ], refeds .RELEASE [RESEARCH_AND_SCHOLARSHIP ],
308
- swamid .RELEASE [(RESEARCH_AND_EDUCATION , EU )], swamid .RELEASE [(RESEARCH_AND_EDUCATION , HEI )],
309
- swamid .RELEASE [(RESEARCH_AND_EDUCATION , NREN )], swamid .RELEASE [SFS_1993_1153 ]))
317
+ expected_attributes_in_all_entity_categories = set (
318
+ itertools .chain (
319
+ swamid .RELEASE ["" ],
320
+ edugain .RELEASE ["" ],
321
+ edugain .RELEASE [COCO ],
322
+ refeds .RELEASE [RESEARCH_AND_SCHOLARSHIP ],
323
+ swamid .RELEASE [(RESEARCH_AND_EDUCATION , EU )],
324
+ swamid .RELEASE [(RESEARCH_AND_EDUCATION , HEI )],
325
+ swamid .RELEASE [(RESEARCH_AND_EDUCATION , NREN )],
326
+ swamid .RELEASE [SFS_1993_1153 ],
327
+ )
328
+ )
310
329
attribute_mapping = {}
311
330
for expected_attribute in expected_attributes_in_all_entity_categories :
312
331
attribute_mapping [expected_attribute .lower ()] = {"saml" : [expected_attribute ]}
@@ -345,8 +364,9 @@ def test_metadata_endpoint(self, context, idp_conf):
345
364
assert headers ["Content-Type" ] == "text/xml"
346
365
assert idp_conf ["entityid" ] in resp .message
347
366
348
- def test_custom_attribute_release_with_less_attributes_than_entity_category (self , context , idp_conf , sp_conf ,
349
- internal_response ):
367
+ def test_custom_attribute_release_with_less_attributes_than_entity_category (
368
+ self , context , idp_conf , sp_conf , internal_response
369
+ ):
350
370
idp_metadata_str = create_metadata_from_config_dict (idp_conf )
351
371
idp_conf ["service" ]["idp" ]["policy" ]["default" ]["entity_categories" ] = ["swamid" ]
352
372
sp_conf ["entity_category" ] = [SFS_1993_1153 ]
@@ -364,8 +384,12 @@ def test_custom_attribute_release_with_less_attributes_than_entity_category(self
364
384
samlfrontend = self .setup_for_authn_req (context , idp_conf , sp_conf , internal_attributes = internal_attributes ,
365
385
extra_config = dict (custom_attribute_release = custom_attributes ))
366
386
387
+ internal_response .requester = sp_conf ["entityid" ]
367
388
resp = self .get_auth_response (samlfrontend , context , internal_response , sp_conf , idp_metadata_str )
368
- assert len (resp .ava .keys ()) == 0
389
+ assert len (resp .ava .keys ()) == (
390
+ len (expected_attributes )
391
+ - len (custom_attributes [internal_response .auth_info .issuer ][internal_response .requester ]["exclude" ])
392
+ )
369
393
370
394
371
395
class TestSAMLMirrorFrontend :
0 commit comments