10
10
from saml2 .mdstore import MetadataStore
11
11
from saml2 .saml import Attribute , NAME_FORMAT_URI
12
12
from saml2 .server import Server
13
+ from saml2 .md import RequestedAttribute
14
+
13
15
14
16
ATTRCONV = ac_factory (full_path ("attributemaps" ))
15
17
sec_config = config .Config ()
@@ -234,6 +236,7 @@ def test_entity_category_import_from_path():
234
236
235
237
236
238
def test_filter_ava_required_attributes_with_no_friendly_name ():
239
+ entity_id = "https://no-friendly-name.example.edu/saml2/metadata/"
237
240
mds = MetadataStore (ATTRCONV , sec_config , disable_ssl_certificate_validation = True )
238
241
mds .imp (
239
242
[
@@ -250,7 +253,6 @@ def test_filter_ava_required_attributes_with_no_friendly_name():
250
253
"entity_categories" : ["swamid" ]
251
254
}
252
255
}
253
-
254
256
policy = Policy (policy_conf , mds )
255
257
256
258
ava = {
@@ -259,13 +261,20 @@ def test_filter_ava_required_attributes_with_no_friendly_name():
259
261
260
262
"c" : ["USA" ],
261
263
"eduPersonTargetedID" : "foo!bar!xyz" ,
262
- "norEduPersonNIN" : "19800101134"
264
+ "norEduPersonNIN" : "19800101134" ,
263
265
}
264
266
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 )
271
280
assert _eq (list (ava .keys ()), ["eduPersonTargetedID" ])
0 commit comments