1010from saml2 .mdstore import MetadataStore
1111from saml2 .saml import Attribute , NAME_FORMAT_URI
1212from saml2 .server import Server
13+ from saml2 .md import RequestedAttribute
14+
1315
1416ATTRCONV = ac_factory (full_path ("attributemaps" ))
1517sec_config = config .Config ()
@@ -234,6 +236,7 @@ def test_entity_category_import_from_path():
234236
235237
236238def test_filter_ava_required_attributes_with_no_friendly_name ():
239+ entity_id = "https://no-friendly-name.example.edu/saml2/metadata/"
237240 mds = MetadataStore (ATTRCONV , sec_config , disable_ssl_certificate_validation = True )
238241 mds .imp (
239242 [
@@ -250,7 +253,6 @@ def test_filter_ava_required_attributes_with_no_friendly_name():
250253 "entity_categories" : ["swamid" ]
251254 }
252255 }
253-
254256 policy = Policy (policy_conf , mds )
255257
256258 ava = {
@@ -259,13 +261,20 @@ def test_filter_ava_required_attributes_with_no_friendly_name():
259261 "mail" : ["derek@nyy.mlb.com" ],
260262 "c" : ["USA" ],
261263 "eduPersonTargetedID" : "foo!bar!xyz" ,
262- "norEduPersonNIN" : "19800101134"
264+ "norEduPersonNIN" : "19800101134" ,
263265 }
264266
265- # Require attribute eduPersonTargetedID but leave out friendlyName in attribute creation
266- edu_person_targeted_id_oid = 'urn:oid:1.3.6.1.4.1.5923.1.1.1.10'
267- edu_person_targeted_id = to_dict (
268- Attribute (name = edu_person_targeted_id_oid ,
269- name_format = NAME_FORMAT_URI ), onts = [mdattr ])
270- ava = policy .filter (ava , "https://no-friendly-name.example.edu/saml2/metadata/" , required = [edu_person_targeted_id ])
267+ attribute_requirements = mds .attribute_requirement (entity_id )
268+ required = attribute_requirements .get ("required" , [])
269+ optional = attribute_requirements .get ("optional" , [])
270+
271+ # ensure the requirements define the eduPersonTargetedID
272+ # without the friendlyName attribute
273+ oid_eptid = 'urn:oid:1.3.6.1.4.1.5923.1.1.1.10'
274+ requested_attribute_eptid = RequestedAttribute (
275+ name = oid_eptid , name_format = NAME_FORMAT_URI , is_required = 'true'
276+ )
277+ assert required == [to_dict (requested_attribute_eptid , onts = [mdattr ])]
278+
279+ ava = policy .filter (ava , entity_id , required = required , optional = optional )
271280 assert _eq (list (ava .keys ()), ["eduPersonTargetedID" ])
0 commit comments