Applied pull request #206
This commit is contained in:
@@ -795,7 +795,7 @@ class MetadataStore(object):
|
|||||||
self.ii += 1
|
self.ii += 1
|
||||||
key = self.ii
|
key = self.ii
|
||||||
kwargs.update(_args)
|
kwargs.update(_args)
|
||||||
_md = MetaData(self.onts, self.attrc, args[0], **kwargs)
|
_md = InMemoryMetaData(self.onts, self.attrc, args[0])
|
||||||
elif typ == "remote":
|
elif typ == "remote":
|
||||||
key = kwargs["url"]
|
key = kwargs["url"]
|
||||||
for _key in ["node_name", "check_validity"]:
|
for _key in ["node_name", "check_validity"]:
|
||||||
|
@@ -3,6 +3,7 @@
|
|||||||
import datetime
|
import datetime
|
||||||
import re
|
import re
|
||||||
from six.moves.urllib.parse import quote_plus
|
from six.moves.urllib.parse import quote_plus
|
||||||
|
from saml2.config import Config
|
||||||
from saml2.httpbase import HTTPBase
|
from saml2.httpbase import HTTPBase
|
||||||
|
|
||||||
from saml2.mdstore import MetadataStore, MetaDataMDX
|
from saml2.mdstore import MetadataStore, MetaDataMDX
|
||||||
@@ -32,7 +33,59 @@ from saml2 import xmlenc
|
|||||||
from pathutils import full_path
|
from pathutils import full_path
|
||||||
|
|
||||||
sec_config = config.Config()
|
sec_config = config.Config()
|
||||||
#sec_config.xmlsec_binary = sigver.get_xmlsec_binary(["/opt/local/bin"])
|
# sec_config.xmlsec_binary = sigver.get_xmlsec_binary(["/opt/local/bin"])
|
||||||
|
|
||||||
|
TEST_METADATA_STRING = """
|
||||||
|
<EntitiesDescriptor
|
||||||
|
xmlns="urn:oasis:names:tc:SAML:2.0:metadata"
|
||||||
|
xmlns:md="urn:oasis:names:tc:SAML:2.0:metadata"
|
||||||
|
xmlns:shibmeta="urn:mace:shibboleth:metadata:1.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
|
||||||
|
Name="urn:mace:example.com:test-1.0">
|
||||||
|
<EntityDescriptor
|
||||||
|
entityID="http://xenosmilus.umdc.umu.se/simplesaml/saml2/idp/metadata.php"
|
||||||
|
xml:base="swamid-1.0/idp.umu.se-saml2.xml">
|
||||||
|
<IDPSSODescriptor protocolSupportEnumeration="urn:oasis:names:tc:SAML:2.0:protocol">
|
||||||
|
<KeyDescriptor>
|
||||||
|
<ds:KeyInfo>
|
||||||
|
<ds:X509Data>
|
||||||
|
<ds:X509Certificate>
|
||||||
|
MIICsDCCAhmgAwIBAgIJAJrzqSSwmDY9MA0GCSqGSIb3DQEBBQUAMEUxCzAJBgNV
|
||||||
|
BAYTAkFVMRMwEQYDVQQIEwpTb21lLVN0YXRlMSEwHwYDVQQKExhJbnRlcm5ldCBX
|
||||||
|
aWRnaXRzIFB0eSBMdGQwHhcNMDkxMDA2MTk0OTQxWhcNMDkxMTA1MTk0OTQxWjBF
|
||||||
|
MQswCQYDVQQGEwJBVTETMBEGA1UECBMKU29tZS1TdGF0ZTEhMB8GA1UEChMYSW50
|
||||||
|
ZXJuZXQgV2lkZ2l0cyBQdHkgTHRkMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKB
|
||||||
|
gQDJg2cms7MqjniT8Fi/XkNHZNPbNVQyMUMXE9tXOdqwYCA1cc8vQdzkihscQMXy
|
||||||
|
3iPw2cMggBu6gjMTOSOxECkuvX5ZCclKr8pXAJM5cY6gVOaVO2PdTZcvDBKGbiaN
|
||||||
|
efiEw5hnoZomqZGp8wHNLAUkwtH9vjqqvxyS/vclc6k2ewIDAQABo4GnMIGkMB0G
|
||||||
|
A1UdDgQWBBRePsKHKYJsiojE78ZWXccK9K4aJTB1BgNVHSMEbjBsgBRePsKHKYJs
|
||||||
|
iojE78ZWXccK9K4aJaFJpEcwRTELMAkGA1UEBhMCQVUxEzARBgNVBAgTClNvbWUt
|
||||||
|
U3RhdGUxITAfBgNVBAoTGEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZIIJAJrzqSSw
|
||||||
|
mDY9MAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEFBQADgYEAJSrKOEzHO7TL5cy6
|
||||||
|
h3qh+3+JAk8HbGBW+cbX6KBCAw/mzU8flK25vnWwXS3dv2FF3Aod0/S7AWNfKib5
|
||||||
|
U/SA9nJaz/mWeF9S0farz9AQFc8/NSzAzaVq7YbM4F6f6N2FRl7GikdXRCed45j6
|
||||||
|
mrPzGzk3ECbupFnqyREH3+ZPSdk=</ds:X509Certificate>
|
||||||
|
</ds:X509Data>
|
||||||
|
</ds:KeyInfo>
|
||||||
|
</KeyDescriptor>
|
||||||
|
<NameIDFormat>urn:oasis:names:tc:SAML:2.0:nameid-format:transient</NameIDFormat>
|
||||||
|
<SingleSignOnService
|
||||||
|
Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect"
|
||||||
|
Location="http://xenosmilus.umdc.umu.se/simplesaml/saml2/idp/metadata.php"/>
|
||||||
|
</IDPSSODescriptor>
|
||||||
|
<Organization>
|
||||||
|
<OrganizationName xml:lang="en">Catalogix</OrganizationName>
|
||||||
|
<OrganizationDisplayName xml:lang="en">Catalogix</OrganizationDisplayName>
|
||||||
|
<OrganizationURL xml:lang="en">http://www.catalogix.se</OrganizationURL>
|
||||||
|
</Organization>
|
||||||
|
<ContactPerson contactType="technical">
|
||||||
|
<SurName>Hedberg</SurName>
|
||||||
|
<EmailAddress>datordrift@catalogix.se</EmailAddress>
|
||||||
|
</ContactPerson>
|
||||||
|
</EntityDescriptor>
|
||||||
|
</EntitiesDescriptor>
|
||||||
|
"""
|
||||||
|
|
||||||
ONTS = {
|
ONTS = {
|
||||||
saml.NAMESPACE: saml,
|
saml.NAMESPACE: saml,
|
||||||
@@ -51,15 +104,15 @@ ATTRCONV = ac_factory(full_path("attributemaps"))
|
|||||||
METADATACONF = {
|
METADATACONF = {
|
||||||
"1": [{
|
"1": [{
|
||||||
"class": "saml2.mdstore.MetaDataFile",
|
"class": "saml2.mdstore.MetaDataFile",
|
||||||
"metadata": [(full_path("swamid-1.0.xml"), )],
|
"metadata": [(full_path("swamid-1.0.xml"),)],
|
||||||
}],
|
}],
|
||||||
"2": [{
|
"2": [{
|
||||||
"class": "saml2.mdstore.MetaDataFile",
|
"class": "saml2.mdstore.MetaDataFile",
|
||||||
"metadata": [(full_path("InCommon-metadata.xml"), )],
|
"metadata": [(full_path("InCommon-metadata.xml"),)],
|
||||||
}],
|
}],
|
||||||
"3": [{
|
"3": [{
|
||||||
"class": "saml2.mdstore.MetaDataFile",
|
"class": "saml2.mdstore.MetaDataFile",
|
||||||
"metadata": [(full_path("extended.xml"), )],
|
"metadata": [(full_path("extended.xml"),)],
|
||||||
}],
|
}],
|
||||||
# "7": [{
|
# "7": [{
|
||||||
# "class": "saml2.mdstore.MetaDataFile",
|
# "class": "saml2.mdstore.MetaDataFile",
|
||||||
@@ -68,32 +121,36 @@ METADATACONF = {
|
|||||||
# {
|
# {
|
||||||
# "class": "saml2.mdstore.MetaDataExtern",
|
# "class": "saml2.mdstore.MetaDataExtern",
|
||||||
# "metadata": [
|
# "metadata": [
|
||||||
# ("https://kalmar2.org/simplesaml/module.php/aggregator/?id=kalmarcentral2&set=saml2",
|
# ("https://kalmar2.org/simplesaml/module.php/aggregator/?id
|
||||||
|
# =kalmarcentral2&set=saml2",
|
||||||
# full_path("kalmar2.pem")), ],
|
# full_path("kalmar2.pem")), ],
|
||||||
# }],
|
# }],
|
||||||
"4": [{
|
"4": [{
|
||||||
"class": "saml2.mdstore.MetaDataFile",
|
"class": "saml2.mdstore.MetaDataFile",
|
||||||
"metadata": [(full_path("metadata_example.xml"), )],
|
"metadata": [(full_path("metadata_example.xml"),)],
|
||||||
}],
|
}],
|
||||||
"5": [{
|
"5": [{
|
||||||
"class": "saml2.mdstore.MetaDataFile",
|
"class": "saml2.mdstore.MetaDataFile",
|
||||||
"metadata": [(full_path("metadata.aaitest.xml"), )],
|
"metadata": [(full_path("metadata.aaitest.xml"),)],
|
||||||
}],
|
}],
|
||||||
"8": [{
|
"8": [{
|
||||||
"class": "saml2.mdstore.MetaDataMD",
|
"class": "saml2.mdstore.MetaDataMD",
|
||||||
"metadata": [(full_path("swamid.md"), )],
|
"metadata": [(full_path("swamid.md"),)],
|
||||||
}],
|
}],
|
||||||
"9": [{
|
"9": [{
|
||||||
"class": "saml2.mdstore.MetaDataFile",
|
"class": "saml2.mdstore.MetaDataFile",
|
||||||
"metadata": [(full_path("metadata"), )]
|
"metadata": [(full_path("metadata"),)]
|
||||||
}],
|
}],
|
||||||
"10": [{
|
"10": [{
|
||||||
"class": "saml2.mdstore.MetaDataExtern",
|
"class": "saml2.mdstore.MetaDataExtern",
|
||||||
"metadata": [
|
"metadata": [
|
||||||
("http://md.incommon.org/InCommon/InCommon-metadata-export.xml",
|
("http://md.incommon.org/InCommon/InCommon-metadata-export.xml",
|
||||||
full_path("inc-md-cert.pem"))]
|
full_path("inc-md-cert.pem"))]
|
||||||
}
|
}],
|
||||||
]
|
"11": [{
|
||||||
|
"class": "saml2.mdstore.InMemoryMetaData",
|
||||||
|
"metadata": [(TEST_METADATA_STRING, )]
|
||||||
|
}],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -295,5 +352,37 @@ def test_load_extern_incommon():
|
|||||||
assert mds
|
assert mds
|
||||||
assert len(mds.keys())
|
assert len(mds.keys())
|
||||||
|
|
||||||
|
|
||||||
|
def test_load_local():
|
||||||
|
# string representation of XML idp definition
|
||||||
|
idp_metadata = open("metadata.xml").read()
|
||||||
|
|
||||||
|
saml_config = Config()
|
||||||
|
|
||||||
|
config_dict = {
|
||||||
|
"metadata": {"inline": idp_metadata}
|
||||||
|
}
|
||||||
|
cfg = saml_config.load(config_dict)
|
||||||
|
assert cfg
|
||||||
|
|
||||||
|
|
||||||
|
def test_load_string():
|
||||||
|
sec_config.xmlsec_binary = sigver.get_xmlsec_binary(["/opt/local/bin"])
|
||||||
|
mds = MetadataStore(ONTS.values(), ATTRCONV, sec_config,
|
||||||
|
disable_ssl_certificate_validation=True)
|
||||||
|
|
||||||
|
mds.imp(METADATACONF["11"])
|
||||||
|
#print(mds)
|
||||||
|
assert len(mds.keys()) == 1
|
||||||
|
idps = mds.with_descriptor("idpsso")
|
||||||
|
|
||||||
|
assert list(idps.keys()) == [
|
||||||
|
'http://xenosmilus.umdc.umu.se/simplesaml/saml2/idp/metadata.php']
|
||||||
|
certs = mds.certs(
|
||||||
|
'http://xenosmilus.umdc.umu.se/simplesaml/saml2/idp/metadata.php',
|
||||||
|
"idpsso", "signing")
|
||||||
|
assert len(certs) == 1
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
test_load_extern_incommon()
|
test_load_string()
|
||||||
|
@@ -32,6 +32,58 @@ from pathutils import full_path
|
|||||||
sec_config = config.Config()
|
sec_config = config.Config()
|
||||||
#sec_config.xmlsec_binary = sigver.get_xmlsec_binary(["/opt/local/bin"])
|
#sec_config.xmlsec_binary = sigver.get_xmlsec_binary(["/opt/local/bin"])
|
||||||
|
|
||||||
|
TEST_METADATA_STRING = """
|
||||||
|
<EntitiesDescriptor
|
||||||
|
xmlns="urn:oasis:names:tc:SAML:2.0:metadata"
|
||||||
|
xmlns:md="urn:oasis:names:tc:SAML:2.0:metadata"
|
||||||
|
xmlns:shibmeta="urn:mace:shibboleth:metadata:1.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
|
||||||
|
Name="urn:mace:example.com:test-1.0">
|
||||||
|
<EntityDescriptor
|
||||||
|
entityID="http://xenosmilus.umdc.umu.se/simplesaml/saml2/idp/metadata.php"
|
||||||
|
xml:base="swamid-1.0/idp.umu.se-saml2.xml">
|
||||||
|
<IDPSSODescriptor protocolSupportEnumeration="urn:oasis:names:tc:SAML:2.0:protocol">
|
||||||
|
<KeyDescriptor>
|
||||||
|
<ds:KeyInfo>
|
||||||
|
<ds:X509Data>
|
||||||
|
<ds:X509Certificate>
|
||||||
|
MIICsDCCAhmgAwIBAgIJ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
||||||
|
</ds:KeyInfo>
|
||||||
|
</KeyDescriptor>
|
||||||
|
<NameIDFormat>urn:oasis:names:tc:SAML:2.0:nameid-format:transient</NameIDFormat>
|
||||||
|
<SingleSignOnService
|
||||||
|
Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect"
|
||||||
|
Location="http://xenosmilus.umdc.umu.se/simplesaml/saml2/idp/metadata.php"/>
|
||||||
|
</IDPSSODescriptor>
|
||||||
|
<Organization>
|
||||||
|
<OrganizationName xml:lang="en">Catalogix</OrganizationName>
|
||||||
|
<OrganizationDisplayName xml:lang="en">Catalogix</OrganizationDisplayName>
|
||||||
|
<OrganizationURL xml:lang="en">http://www.catalogix.se</OrganizationURL>
|
||||||
|
</Organization>
|
||||||
|
<ContactPerson contactType="technical">
|
||||||
|
<SurName>Hedberg</SurName>
|
||||||
|
<EmailAddress>datordrift@catalogix.se</EmailAddress>
|
||||||
|
</ContactPerson>
|
||||||
|
</EntityDescriptor>
|
||||||
|
</EntitiesDescriptor>
|
||||||
|
"""
|
||||||
|
|
||||||
ONTS = {
|
ONTS = {
|
||||||
saml.NAMESPACE: saml,
|
saml.NAMESPACE: saml,
|
||||||
mdui.NAMESPACE: mdui,
|
mdui.NAMESPACE: mdui,
|
||||||
@@ -79,6 +131,9 @@ METADATACONF = {
|
|||||||
"remote": [
|
"remote": [
|
||||||
{"url": "http://md.incommon.org/InCommon/InCommon-metadata-export.xml",
|
{"url": "http://md.incommon.org/InCommon/InCommon-metadata-export.xml",
|
||||||
"cert": full_path("inc-md-cert.pem")}]
|
"cert": full_path("inc-md-cert.pem")}]
|
||||||
|
},
|
||||||
|
"11": {
|
||||||
|
"inline": [TEST_METADATA_STRING]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -280,5 +335,23 @@ def test_load_external():
|
|||||||
assert len(mds) == 1 # One source
|
assert len(mds) == 1 # One source
|
||||||
assert len(mds.keys()) > 1 # number of idps
|
assert len(mds.keys()) > 1 # number of idps
|
||||||
|
|
||||||
|
|
||||||
|
def test_load_string():
|
||||||
|
sec_config.xmlsec_binary = sigver.get_xmlsec_binary(["/opt/local/bin"])
|
||||||
|
mds = MetadataStore(ONTS.values(), ATTRCONV, sec_config,
|
||||||
|
disable_ssl_certificate_validation=True)
|
||||||
|
|
||||||
|
mds.imp(METADATACONF["11"])
|
||||||
|
print(mds)
|
||||||
|
assert len(mds.keys()) == 1
|
||||||
|
idps = mds.with_descriptor("idpsso")
|
||||||
|
|
||||||
|
assert idps.keys() == [
|
||||||
|
'http://xenosmilus.umdc.umu.se/simplesaml/saml2/idp/metadata.php']
|
||||||
|
certs = mds.certs(
|
||||||
|
'http://xenosmilus.umdc.umu.se/simplesaml/saml2/idp/metadata.php',
|
||||||
|
"idpsso", "signing")
|
||||||
|
assert len(certs) == 1
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
test_load_external()
|
test_load_external()
|
||||||
|
Reference in New Issue
Block a user