Skip to content

Commit 6744f80

Browse files
author
Roland Hedberg
committed
Allow name_format for requested attributes to be set in the configuration.
1 parent 3ddbb1a commit 6744f80

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

tests/test_39_metadata.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import copy
2+
from saml2.config import SPConfig
3+
from saml2.metadata import entity_descriptor
4+
from saml2.saml import NAME_FORMAT_URI, NAME_FORMAT_BASIC
5+
6+
__author__ = 'roland'
7+
8+
sp_conf = {
9+
"entityid": "urn:mace:umu.se:saml:roland:sp",
10+
"name": "Rolands SP",
11+
"service": {
12+
"sp": {
13+
"endpoints": {
14+
"assertion_consumer_service": [
15+
"http://lingon.catalogix.se:8087/"],
16+
},
17+
"required_attributes": ["surName", "givenName", "mail"],
18+
"optional_attributes": ["title"],
19+
"idp": {
20+
"": "https://example.com/saml2/idp/SSOService.php",
21+
},
22+
"authn_requests_signed": True,
23+
"logout_requests_signed": True,
24+
}
25+
},
26+
}
27+
28+
29+
def test_requested_attribute_name_format():
30+
cnf = SPConfig().load(sp_conf, metadata_construction=True)
31+
ed = entity_descriptor(cnf)
32+
33+
assert len(ed.spsso_descriptor.attribute_consuming_service) == 1
34+
acs = ed.spsso_descriptor.attribute_consuming_service[0]
35+
assert len(acs.requested_attribute) == 4
36+
for req_attr in acs.requested_attribute:
37+
assert req_attr.name_format == NAME_FORMAT_URI
38+
39+
sp2 = copy.copy(sp_conf)
40+
sp2["service"]["sp"]["requested_attribute_name_format"] = NAME_FORMAT_BASIC
41+
42+
cnf2 = SPConfig().load(sp2, metadata_construction=True)
43+
ed = entity_descriptor(cnf2)
44+
acs = ed.spsso_descriptor.attribute_consuming_service[0]
45+
assert len(acs.requested_attribute) == 4
46+
for req_attr in acs.requested_attribute:
47+
assert req_attr.name_format == NAME_FORMAT_BASIC
48+
49+
50+
if __name__ == '__main__':
51+
test_requested_attribute_name_format()

0 commit comments

Comments
 (0)