@@ -285,28 +285,47 @@ def test_acr_mapping_per_idp_in_authn_response(self, context, idp_conf, sp_conf,
285285 authn_context_class_ref = resp .assertion .authn_statement [0 ].authn_context .authn_context_class_ref
286286 assert authn_context_class_ref .text == expected_loa
287287
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+ ):
299310 idp_metadata_str = create_metadata_from_config_dict (idp_conf )
300311 idp_conf ["service" ]["idp" ]["policy" ]["default" ]["entity_categories" ] = [entity_category_module ]
301312 if all (entity_category ): # don't insert empty entity category
302313 sp_conf ["entity_category" ] = entity_category
303314 if entity_category == [COCO ]:
304315 sp_conf ["service" ]["sp" ]["required_attributes" ] = expected_attributes
305316
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+ )
310329 attribute_mapping = {}
311330 for expected_attribute in expected_attributes_in_all_entity_categories :
312331 attribute_mapping [expected_attribute .lower ()] = {"saml" : [expected_attribute ]}
@@ -345,8 +364,9 @@ def test_metadata_endpoint(self, context, idp_conf):
345364 assert headers ["Content-Type" ] == "text/xml"
346365 assert idp_conf ["entityid" ] in resp .message
347366
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+ ):
350370 idp_metadata_str = create_metadata_from_config_dict (idp_conf )
351371 idp_conf ["service" ]["idp" ]["policy" ]["default" ]["entity_categories" ] = ["swamid" ]
352372 sp_conf ["entity_category" ] = [SFS_1993_1153 ]
@@ -364,8 +384,12 @@ def test_custom_attribute_release_with_less_attributes_than_entity_category(self
364384 samlfrontend = self .setup_for_authn_req (context , idp_conf , sp_conf , internal_attributes = internal_attributes ,
365385 extra_config = dict (custom_attribute_release = custom_attributes ))
366386
387+ internal_response .requester = sp_conf ["entityid" ]
367388 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+ )
369393
370394
371395class TestSAMLMirrorFrontend :
0 commit comments