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