Skip to content

Commit 86dec17

Browse files
author
Roland Hedberg
committed
Fixed name_format bug. Modified test to check for name_format specification.
1 parent b40dfab commit 86dec17

File tree

4 files changed

+126
-10
lines changed

4 files changed

+126
-10
lines changed

src/saml2/assertion.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ def get_name_form(self, sp_entity_id):
405405
:retur: The format
406406
"""
407407

408-
return self.get("name_format", sp_entity_id, NAME_FORMAT_URI)
408+
return self.get("name_form", sp_entity_id, NAME_FORMAT_URI)
409409

410410
def get_lifetime(self, sp_entity_id):
411411
""" The lifetime of the assertion

tests/idp_conf.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from saml2 import BINDING_SOAP
22
from saml2 import BINDING_HTTP_REDIRECT
33
from saml2 import BINDING_HTTP_POST
4-
from saml2.saml import NAMEID_FORMAT_PERSISTENT
4+
from saml2.saml import NAMEID_FORMAT_PERSISTENT, NAME_FORMAT_BASIC
55
from saml2.saml import NAME_FORMAT_URI
66

77
from pathutils import full_path
@@ -30,10 +30,11 @@
3030
"urn:mace:example.com:saml:roland:sp": {
3131
"lifetime": {"minutes": 5},
3232
"nameid_format": NAMEID_FORMAT_PERSISTENT,
33-
# "attribute_restrictions":{
34-
# "givenName": None,
35-
# "surName": None,
36-
# }
33+
},
34+
"https://example.com/sp": {
35+
"lifetime": {"minutes": 5},
36+
"nameid_format": NAMEID_FORMAT_PERSISTENT,
37+
"name_form": NAME_FORMAT_BASIC
3738
}
3839
},
3940
"subject_data": full_path("subject_data.db"),
@@ -48,6 +49,7 @@
4849
"metadata": [{
4950
"class": "saml2.mdstore.MetaDataFile",
5051
"metadata": [(full_path("metadata_sp_1.xml"), ),
52+
(full_path("metadata_sp_2.xml"), ),
5153
(full_path("vo_metadata.xml"), )],
5254
}],
5355
"attribute_map_dir": full_path("attributemaps"),

tests/metadata_sp_2.xml

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<ns0:EntitiesDescriptor xmlns:ns0="urn:oasis:names:tc:SAML:2.0:metadata"
3+
xmlns:ns1="http://www.w3.org/2000/09/xmldsig#">
4+
<ns0:EntityDescriptor entityID="https://example.com/sp">
5+
<ns0:SPSSODescriptor AuthnRequestsSigned="false"
6+
WantAssertionsSigned="true"
7+
protocolSupportEnumeration="urn:oasis:names:tc:SAML:2.0:protocol">
8+
<ns0:KeyDescriptor use="signing">
9+
<ns1:KeyInfo>
10+
<ns1:X509Data>
11+
<ns1:X509Certificate>
12+
MIICsDCCAhmgAwIBAgIJAJrzqSSwmDY9MA0GCSqGSIb3DQEBBQUAMEUxCzAJBgNV
13+
BAYTAkFVMRMwEQYDVQQIEwpTb21lLVN0YXRlMSEwHwYDVQQKExhJbnRlcm5ldCBX
14+
aWRnaXRzIFB0eSBMdGQwHhcNMDkxMDA2MTk0OTQxWhcNMDkxMTA1MTk0OTQxWjBF
15+
MQswCQYDVQQGEwJBVTETMBEGA1UECBMKU29tZS1TdGF0ZTEhMB8GA1UEChMYSW50
16+
ZXJuZXQgV2lkZ2l0cyBQdHkgTHRkMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKB
17+
gQDJg2cms7MqjniT8Fi/XkNHZNPbNVQyMUMXE9tXOdqwYCA1cc8vQdzkihscQMXy
18+
3iPw2cMggBu6gjMTOSOxECkuvX5ZCclKr8pXAJM5cY6gVOaVO2PdTZcvDBKGbiaN
19+
efiEw5hnoZomqZGp8wHNLAUkwtH9vjqqvxyS/vclc6k2ewIDAQABo4GnMIGkMB0G
20+
A1UdDgQWBBRePsKHKYJsiojE78ZWXccK9K4aJTB1BgNVHSMEbjBsgBRePsKHKYJs
21+
iojE78ZWXccK9K4aJaFJpEcwRTELMAkGA1UEBhMCQVUxEzARBgNVBAgTClNvbWUt
22+
U3RhdGUxITAfBgNVBAoTGEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZIIJAJrzqSSw
23+
mDY9MAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEFBQADgYEAJSrKOEzHO7TL5cy6
24+
h3qh+3+JAk8HbGBW+cbX6KBCAw/mzU8flK25vnWwXS3dv2FF3Aod0/S7AWNfKib5
25+
U/SA9nJaz/mWeF9S0farz9AQFc8/NSzAzaVq7YbM4F6f6N2FRl7GikdXRCed45j6
26+
mrPzGzk3ECbupFnqyREH3+ZPSdk=
27+
</ns1:X509Certificate>
28+
</ns1:X509Data>
29+
</ns1:KeyInfo>
30+
</ns0:KeyDescriptor>
31+
<ns0:KeyDescriptor use="encryption">
32+
<ns1:KeyInfo>
33+
<ns1:X509Data>
34+
<ns1:X509Certificate>
35+
MIICHzCCAYgCAQEwDQYJKoZIhvcNAQELBQAwWDELMAkGA1UEBhMCenoxCzAJBgNV
36+
BAgMAnp6MQ0wCwYDVQQHDAR6enp6MQ4wDAYDVQQKDAVaenp6ejEOMAwGA1UECwwF
37+
Wnp6enoxDTALBgNVBAMMBHRlc3QwHhcNMTUwNjAyMDc0MzAxWhcNMjUwNTMwMDc0
38+
MzAxWjBYMQswCQYDVQQGEwJ6ejELMAkGA1UECAwCenoxDTALBgNVBAcMBHp6enox
39+
DjAMBgNVBAoMBVp6enp6MQ4wDAYDVQQLDAVaenp6ejENMAsGA1UEAwwEdGVzdDCB
40+
nzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEA41tJCTPuG2lirbztuGbBlzbzSipM
41+
EzM+zluWegUaoUjqtlgNHOTQqTJOqw/GdjkxRKJT6IxI3/HVcnfw7P4a4xSkL/ME
42+
IG3VyzedWEyLIHeofoQSTvr84ZdD0+Gk+zNCSqOQC7UuqpOLbMKK1tgZ8Mr7BkgI
43+
p8H3lreLf29Sd5MCAwEAATANBgkqhkiG9w0BAQsFAAOBgQB0EXxy5+hsB7Rid7Gy
44+
CZrAObpaC4nbyPPW/vccFKmEkYtlygEPgky7D9AGsVSaTc/YxPZcanY+vKoRIsiR
45+
6ZitIUU5b+NnHcdj6289tUQ0iHj5jgVyv8wYHvPntTnqH2S7he0talLER8ITYToh
46+
2wz3u7waz/GypMeA/suhoEfxew==
47+
</ns1:X509Certificate>
48+
</ns1:X509Data>
49+
</ns1:KeyInfo>
50+
</ns0:KeyDescriptor>
51+
<ns0:KeyDescriptor use="encryption">
52+
<ns1:KeyInfo>
53+
<ns1:X509Data>
54+
<ns1:X509Certificate>
55+
MIICHzCCAYgCAQEwDQYJKoZIhvcNAQELBQAwWDELMAkGA1UEBhMCenoxCzAJBgNV
56+
BAgMAnp6MQ0wCwYDVQQHDAR6enp6MQ4wDAYDVQQKDAVaenp6ejEOMAwGA1UECwwF
57+
Wnp6enoxDTALBgNVBAMMBHRlc3QwHhcNMTUwNjAyMDc0MjI2WhcNMjUwNTMwMDc0
58+
MjI2WjBYMQswCQYDVQQGEwJ6ejELMAkGA1UECAwCenoxDTALBgNVBAcMBHp6enox
59+
DjAMBgNVBAoMBVp6enp6MQ4wDAYDVQQLDAVaenp6ejENMAsGA1UEAwwEdGVzdDCB
60+
nzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAx3I/NFlP1wbHfRZckJn4z1HX5nnY
61+
QhQ3ekxEJmTTaj/1BvlZBmvgV40SBzH4nP1sT02xoQo7+vHItFAzaJlF2oBXsSxj
62+
aZMGu/gkVbaHP9cYKvskhOjOJ4XArrUnKMTb1jZ+XkkOuot1NLE7/dTILF8ahHU2
63+
omYNASLnxHN3bnkCAwEAATANBgkqhkiG9w0BAQsFAAOBgQCQam1Oz7iQcD9+OurB
64+
M5a+Hth53m5hbAFuguSvERPCuJ/CfP1+g7CIZN/GnsIsg9QW77NvdOyxjXxzoJJm
65+
okl1qz/qy3FY3mJ0gIUxDyPD9DL3c9/03MDv5YmWsoP+HNqK8QtNJ/JDEOhBr/Eo
66+
/MokRo4gtMNeLF/soveWNoNiUg==
67+
</ns1:X509Certificate>
68+
</ns1:X509Data>
69+
</ns1:KeyInfo>
70+
</ns0:KeyDescriptor>
71+
<ns0:AssertionConsumerService
72+
Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST"
73+
Location="http://lingon.catalogix.se:8087/" index="1"/>
74+
<ns0:AttributeConsumingService index="1">
75+
<ns0:ServiceName xml:lang="en">
76+
urn:mace:example.com:saml:roland:sp
77+
</ns0:ServiceName>
78+
<ns0:ServiceDescription xml:lang="en">My own SP
79+
</ns0:ServiceDescription>
80+
<ns0:RequestedAttribute FriendlyName="surName"
81+
Name="urn:oid:2.5.4.4"
82+
NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri"
83+
isRequired="true"/>
84+
<ns0:RequestedAttribute FriendlyName="givenName"
85+
Name="urn:oid:2.5.4.42"
86+
NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri"
87+
isRequired="true"/>
88+
<ns0:RequestedAttribute FriendlyName="mail"
89+
Name="urn:oid:0.9.2342.19200300.100.1.3"
90+
NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri"
91+
isRequired="true"/>
92+
<ns0:RequestedAttribute FriendlyName="title"
93+
Name="urn:oid:2.5.4.12"
94+
NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri"
95+
isRequired="false"/>
96+
</ns0:AttributeConsumingService>
97+
</ns0:SPSSODescriptor>
98+
<ns0:Organization>
99+
<ns0:OrganizationName xml:lang="se">AB Exempel
100+
</ns0:OrganizationName>
101+
<ns0:OrganizationDisplayName xml:lang="se">AB Exempel
102+
</ns0:OrganizationDisplayName>
103+
<ns0:OrganizationURL xml:lang="en">http://www.example.org
104+
</ns0:OrganizationURL>
105+
</ns0:Organization>
106+
<ns0:ContactPerson contactType="technical">
107+
<ns0:GivenName>Roland</ns0:GivenName>
108+
<ns0:SurName>Hedberg</ns0:SurName>
109+
<ns0:EmailAddress>[email protected]</ns0:EmailAddress>
110+
<ns0:EmailAddress>[email protected]</ns0:EmailAddress>
111+
<ns0:TelephoneNumber>+46 70 100 0000</ns0:TelephoneNumber>
112+
</ns0:ContactPerson>
113+
</ns0:EntityDescriptor>
114+
</ns0:EntitiesDescriptor>

tests/test_50_server.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ def test_parse_ok_request(self):
271271

272272
def test_sso_response_with_identity(self):
273273
name_id = self.server.ident.transient_nameid(
274-
"urn:mace:example.com:saml:roland:sp", "id12")
274+
"https://example.com/sp", "id12")
275275
resp = self.server.create_authn_response(
276276
{
277277
"eduPersonEntitlement": "Short stop",
@@ -282,7 +282,7 @@ def test_sso_response_with_identity(self):
282282
},
283283
"id12", # in_response_to
284284
"http://localhost:8087/", # destination
285-
"urn:mace:example.com:saml:roland:sp", # sp_entity_id
285+
"https://example.com/sp", # sp_entity_id
286286
name_id=name_id,
287287
authn=AUTHN
288288
)
@@ -310,8 +310,8 @@ def test_sso_response_with_identity(self):
310310
if attr.friendly_name == "givenName":
311311
break
312312
assert len(attr.attribute_value) == 1
313-
assert attr.name == "urn:oid:2.5.4.42"
314-
assert attr.name_format == "urn:oasis:names:tc:SAML:2.0:attrname-format:uri"
313+
assert attr.name == "urn:mace:dir:attribute-def:givenName"
314+
assert attr.name_format == "urn:oasis:names:tc:SAML:2.0:attrname-format:basic"
315315
value = attr.attribute_value[0]
316316
assert value.text.strip() == "Derek"
317317
assert value.get_type() == "xs:string"

0 commit comments

Comments
 (0)