Skip to content

Commit b7be49d

Browse files
author
Roland Hedberg
committed
Applied pull request #206
1 parent d9df219 commit b7be49d

File tree

3 files changed

+175
-13
lines changed

3 files changed

+175
-13
lines changed

src/saml2/mdstore.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,7 @@ def load(self, typ, *args, **kwargs):
795795
self.ii += 1
796796
key = self.ii
797797
kwargs.update(_args)
798-
_md = MetaData(self.onts, self.attrc, args[0], **kwargs)
798+
_md = InMemoryMetaData(self.onts, self.attrc, args[0])
799799
elif typ == "remote":
800800
key = kwargs["url"]
801801
for _key in ["node_name", "check_validity"]:

tests/test_30_mdstore.py

Lines changed: 101 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import datetime
44
import re
55
from six.moves.urllib.parse import quote_plus
6+
from saml2.config import Config
67
from saml2.httpbase import HTTPBase
78

89
from saml2.mdstore import MetadataStore, MetaDataMDX
@@ -32,7 +33,59 @@
3233
from pathutils import full_path
3334

3435
sec_config = config.Config()
35-
#sec_config.xmlsec_binary = sigver.get_xmlsec_binary(["/opt/local/bin"])
36+
# sec_config.xmlsec_binary = sigver.get_xmlsec_binary(["/opt/local/bin"])
37+
38+
TEST_METADATA_STRING = """
39+
<EntitiesDescriptor
40+
xmlns="urn:oasis:names:tc:SAML:2.0:metadata"
41+
xmlns:md="urn:oasis:names:tc:SAML:2.0:metadata"
42+
xmlns:shibmeta="urn:mace:shibboleth:metadata:1.0"
43+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
44+
xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
45+
Name="urn:mace:example.com:test-1.0">
46+
<EntityDescriptor
47+
entityID="http://xenosmilus.umdc.umu.se/simplesaml/saml2/idp/metadata.php"
48+
xml:base="swamid-1.0/idp.umu.se-saml2.xml">
49+
<IDPSSODescriptor protocolSupportEnumeration="urn:oasis:names:tc:SAML:2.0:protocol">
50+
<KeyDescriptor>
51+
<ds:Key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yDescriptor>
72+
<NameIDFormat>urn:oasis:names:tc:SAML:2.0:nameid-format:transient</NameIDFormat>
73+
<SingleSignOnService
74+
Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect"
75+
Location="http://xenosmilus.umdc.umu.se/simplesaml/saml2/idp/metadata.php"/>
76+
</IDPSSODescriptor>
77+
<Organization>
78+
<OrganizationName xml:lang="en">Catalogix</OrganizationName>
79+
<OrganizationDisplayName xml:lang="en">Catalogix</OrganizationDisplayName>
80+
<OrganizationURL xml:lang="en">http://www.catalogix.se</OrganizationURL>
81+
</Organization>
82+
<ContactPerson contactType="technical">
83+
<SurName>Hedberg</SurName>
84+
<EmailAddress>[email protected]</EmailAddress>
85+
</ContactPerson>
86+
</EntityDescriptor>
87+
</EntitiesDescriptor>
88+
"""
3689

3790
ONTS = {
3891
saml.NAMESPACE: saml,
@@ -51,15 +104,15 @@
51104
METADATACONF = {
52105
"1": [{
53106
"class": "saml2.mdstore.MetaDataFile",
54-
"metadata": [(full_path("swamid-1.0.xml"), )],
107+
"metadata": [(full_path("swamid-1.0.xml"),)],
55108
}],
56109
"2": [{
57110
"class": "saml2.mdstore.MetaDataFile",
58-
"metadata": [(full_path("InCommon-metadata.xml"), )],
111+
"metadata": [(full_path("InCommon-metadata.xml"),)],
59112
}],
60113
"3": [{
61114
"class": "saml2.mdstore.MetaDataFile",
62-
"metadata": [(full_path("extended.xml"), )],
115+
"metadata": [(full_path("extended.xml"),)],
63116
}],
64117
# "7": [{
65118
# "class": "saml2.mdstore.MetaDataFile",
@@ -68,32 +121,36 @@
68121
# {
69122
# "class": "saml2.mdstore.MetaDataExtern",
70123
# "metadata": [
71-
# ("https://kalmar2.org/simplesaml/module.php/aggregator/?id=kalmarcentral2&set=saml2",
124+
# ("https://kalmar2.org/simplesaml/module.php/aggregator/?id
125+
# =kalmarcentral2&set=saml2",
72126
# full_path("kalmar2.pem")), ],
73127
# }],
74128
"4": [{
75129
"class": "saml2.mdstore.MetaDataFile",
76-
"metadata": [(full_path("metadata_example.xml"), )],
130+
"metadata": [(full_path("metadata_example.xml"),)],
77131
}],
78132
"5": [{
79133
"class": "saml2.mdstore.MetaDataFile",
80-
"metadata": [(full_path("metadata.aaitest.xml"), )],
134+
"metadata": [(full_path("metadata.aaitest.xml"),)],
81135
}],
82136
"8": [{
83137
"class": "saml2.mdstore.MetaDataMD",
84-
"metadata": [(full_path("swamid.md"), )],
138+
"metadata": [(full_path("swamid.md"),)],
85139
}],
86140
"9": [{
87141
"class": "saml2.mdstore.MetaDataFile",
88-
"metadata": [(full_path("metadata"), )]
142+
"metadata": [(full_path("metadata"),)]
89143
}],
90144
"10": [{
91145
"class": "saml2.mdstore.MetaDataExtern",
92146
"metadata": [
93147
("http://md.incommon.org/InCommon/InCommon-metadata-export.xml",
94148
full_path("inc-md-cert.pem"))]
95-
}
96-
]
149+
}],
150+
"11": [{
151+
"class": "saml2.mdstore.InMemoryMetaData",
152+
"metadata": [(TEST_METADATA_STRING, )]
153+
}],
97154
}
98155

99156

@@ -295,5 +352,37 @@ def test_load_extern_incommon():
295352
assert mds
296353
assert len(mds.keys())
297354

355+
356+
def test_load_local():
357+
# string representation of XML idp definition
358+
idp_metadata = open("metadata.xml").read()
359+
360+
saml_config = Config()
361+
362+
config_dict = {
363+
"metadata": {"inline": idp_metadata}
364+
}
365+
cfg = saml_config.load(config_dict)
366+
assert cfg
367+
368+
369+
def test_load_string():
370+
sec_config.xmlsec_binary = sigver.get_xmlsec_binary(["/opt/local/bin"])
371+
mds = MetadataStore(ONTS.values(), ATTRCONV, sec_config,
372+
disable_ssl_certificate_validation=True)
373+
374+
mds.imp(METADATACONF["11"])
375+
#print(mds)
376+
assert len(mds.keys()) == 1
377+
idps = mds.with_descriptor("idpsso")
378+
379+
assert list(idps.keys()) == [
380+
'http://xenosmilus.umdc.umu.se/simplesaml/saml2/idp/metadata.php']
381+
certs = mds.certs(
382+
'http://xenosmilus.umdc.umu.se/simplesaml/saml2/idp/metadata.php',
383+
"idpsso", "signing")
384+
assert len(certs) == 1
385+
386+
298387
if __name__ == "__main__":
299-
test_load_extern_incommon()
388+
test_load_string()

tests/test_30_mdstore_old.py

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,58 @@
3232
sec_config = config.Config()
3333
#sec_config.xmlsec_binary = sigver.get_xmlsec_binary(["/opt/local/bin"])
3434

35+
TEST_METADATA_STRING = """
36+
<EntitiesDescriptor
37+
xmlns="urn:oasis:names:tc:SAML:2.0:metadata"
38+
xmlns:md="urn:oasis:names:tc:SAML:2.0:metadata"
39+
xmlns:shibmeta="urn:mace:shibboleth:metadata:1.0"
40+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
41+
xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
42+
Name="urn:mace:example.com:test-1.0">
43+
<EntityDescriptor
44+
entityID="http://xenosmilus.umdc.umu.se/simplesaml/saml2/idp/metadata.php"
45+
xml:base="swamid-1.0/idp.umu.se-saml2.xml">
46+
<IDPSSODescriptor protocolSupportEnumeration="urn:oasis:names:tc:SAML:2.0:protocol">
47+
<KeyDescriptor>
48+
<ds:KeyInfo>
49+
<ds:X509Data>
50+
<ds:X509Certificate>
51+
MIICsDCCAhmgAwIBAgIJAJrzqSSwmDY9MA0GCSqGSIb3DQEBBQUAMEUxCzAJBgNV
52+
BAYTAkFVMRMwEQYDVQQIEwpTb21lLVN0YXRlMSEwHwYDVQQKExhJbnRlcm5ldCBX
53+
aWRnaXRzIFB0eSBMdGQwHhcNMDkxMDA2MTk0OTQxWhcNMDkxMTA1MTk0OTQxWjBF
54+
MQswCQYDVQQGEwJBVTETMBEGA1UECBMKU29tZS1TdGF0ZTEhMB8GA1UEChMYSW50
55+
ZXJuZXQgV2lkZ2l0cyBQdHkgTHRkMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKB
56+
gQDJg2cms7MqjniT8Fi/XkNHZNPbNVQyMUMXE9tXOdqwYCA1cc8vQdzkihscQMXy
57+
3iPw2cMggBu6gjMTOSOxECkuvX5ZCclKr8pXAJM5cY6gVOaVO2PdTZcvDBKGbiaN
58+
efiEw5hnoZomqZGp8wHNLAUkwtH9vjqqvxyS/vclc6k2ewIDAQABo4GnMIGkMB0G
59+
A1UdDgQWBBRePsKHKYJsiojE78ZWXccK9K4aJTB1BgNVHSMEbjBsgBRePsKHKYJs
60+
iojE78ZWXccK9K4aJaFJpEcwRTELMAkGA1UEBhMCQVUxEzARBgNVBAgTClNvbWUt
61+
U3RhdGUxITAfBgNVBAoTGEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZIIJAJrzqSSw
62+
mDY9MAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEFBQADgYEAJSrKOEzHO7TL5cy6
63+
h3qh+3+JAk8HbGBW+cbX6KBCAw/mzU8flK25vnWwXS3dv2FF3Aod0/S7AWNfKib5
64+
U/SA9nJaz/mWeF9S0farz9AQFc8/NSzAzaVq7YbM4F6f6N2FRl7GikdXRCed45j6
65+
mrPzGzk3ECbupFnqyREH3+ZPSdk=</ds:X509Certificate>
66+
</ds:X509Data>
67+
</ds:KeyInfo>
68+
</KeyDescriptor>
69+
<NameIDFormat>urn:oasis:names:tc:SAML:2.0:nameid-format:transient</NameIDFormat>
70+
<SingleSignOnService
71+
Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect"
72+
Location="http://xenosmilus.umdc.umu.se/simplesaml/saml2/idp/metadata.php"/>
73+
</IDPSSODescriptor>
74+
<Organization>
75+
<OrganizationName xml:lang="en">Catalogix</OrganizationName>
76+
<OrganizationDisplayName xml:lang="en">Catalogix</OrganizationDisplayName>
77+
<OrganizationURL xml:lang="en">http://www.catalogix.se</OrganizationURL>
78+
</Organization>
79+
<ContactPerson contactType="technical">
80+
<SurName>Hedberg</SurName>
81+
<EmailAddress>[email protected]</EmailAddress>
82+
</ContactPerson>
83+
</EntityDescriptor>
84+
</EntitiesDescriptor>
85+
"""
86+
3587
ONTS = {
3688
saml.NAMESPACE: saml,
3789
mdui.NAMESPACE: mdui,
@@ -79,6 +131,9 @@
79131
"remote": [
80132
{"url": "http://md.incommon.org/InCommon/InCommon-metadata-export.xml",
81133
"cert": full_path("inc-md-cert.pem")}]
134+
},
135+
"11": {
136+
"inline": [TEST_METADATA_STRING]
82137
}
83138
}
84139

@@ -280,5 +335,23 @@ def test_load_external():
280335
assert len(mds) == 1 # One source
281336
assert len(mds.keys()) > 1 # number of idps
282337

338+
339+
def test_load_string():
340+
sec_config.xmlsec_binary = sigver.get_xmlsec_binary(["/opt/local/bin"])
341+
mds = MetadataStore(ONTS.values(), ATTRCONV, sec_config,
342+
disable_ssl_certificate_validation=True)
343+
344+
mds.imp(METADATACONF["11"])
345+
print(mds)
346+
assert len(mds.keys()) == 1
347+
idps = mds.with_descriptor("idpsso")
348+
349+
assert idps.keys() == [
350+
'http://xenosmilus.umdc.umu.se/simplesaml/saml2/idp/metadata.php']
351+
certs = mds.certs(
352+
'http://xenosmilus.umdc.umu.se/simplesaml/saml2/idp/metadata.php',
353+
"idpsso", "signing")
354+
assert len(certs) == 1
355+
283356
if __name__ == "__main__":
284357
test_load_external()

0 commit comments

Comments
 (0)