|
3 | 3 | import datetime
|
4 | 4 | import re
|
5 | 5 | from six.moves.urllib.parse import quote_plus
|
| 6 | +from saml2.config import Config |
6 | 7 | from saml2.httpbase import HTTPBase
|
7 | 8 |
|
8 | 9 | from saml2.mdstore import MetadataStore, MetaDataMDX
|
|
32 | 33 | from pathutils import full_path
|
33 | 34 |
|
34 | 35 | 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:KeyInfo> |
| 52 | + <ds:X509Data> |
| 53 | + <ds:X509Certificate> |
| 54 | + MIICsDCCAhmgAwIBAgIJAJrzqSSwmDY9MA0GCSqGSIb3DQEBBQUAMEUxCzAJBgNV |
| 55 | + BAYTAkFVMRMwEQYDVQQIEwpTb21lLVN0YXRlMSEwHwYDVQQKExhJbnRlcm5ldCBX |
| 56 | + aWRnaXRzIFB0eSBMdGQwHhcNMDkxMDA2MTk0OTQxWhcNMDkxMTA1MTk0OTQxWjBF |
| 57 | + MQswCQYDVQQGEwJBVTETMBEGA1UECBMKU29tZS1TdGF0ZTEhMB8GA1UEChMYSW50 |
| 58 | + ZXJuZXQgV2lkZ2l0cyBQdHkgTHRkMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKB |
| 59 | + gQDJg2cms7MqjniT8Fi/XkNHZNPbNVQyMUMXE9tXOdqwYCA1cc8vQdzkihscQMXy |
| 60 | + 3iPw2cMggBu6gjMTOSOxECkuvX5ZCclKr8pXAJM5cY6gVOaVO2PdTZcvDBKGbiaN |
| 61 | + efiEw5hnoZomqZGp8wHNLAUkwtH9vjqqvxyS/vclc6k2ewIDAQABo4GnMIGkMB0G |
| 62 | + A1UdDgQWBBRePsKHKYJsiojE78ZWXccK9K4aJTB1BgNVHSMEbjBsgBRePsKHKYJs |
| 63 | + iojE78ZWXccK9K4aJaFJpEcwRTELMAkGA1UEBhMCQVUxEzARBgNVBAgTClNvbWUt |
| 64 | + U3RhdGUxITAfBgNVBAoTGEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZIIJAJrzqSSw |
| 65 | + mDY9MAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEFBQADgYEAJSrKOEzHO7TL5cy6 |
| 66 | + h3qh+3+JAk8HbGBW+cbX6KBCAw/mzU8flK25vnWwXS3dv2FF3Aod0/S7AWNfKib5 |
| 67 | + U/SA9nJaz/mWeF9S0farz9AQFc8/NSzAzaVq7YbM4F6f6N2FRl7GikdXRCed45j6 |
| 68 | + mrPzGzk3ECbupFnqyREH3+ZPSdk=</ds:X509Certificate> |
| 69 | + </ds:X509Data> |
| 70 | + </ds:KeyInfo> |
| 71 | + </KeyDescriptor> |
| 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 | +""" |
36 | 89 |
|
37 | 90 | ONTS = {
|
38 | 91 | saml.NAMESPACE: saml,
|
|
51 | 104 | METADATACONF = {
|
52 | 105 | "1": [{
|
53 | 106 | "class": "saml2.mdstore.MetaDataFile",
|
54 |
| - "metadata": [(full_path("swamid-1.0.xml"), )], |
| 107 | + "metadata": [(full_path("swamid-1.0.xml"),)], |
55 | 108 | }],
|
56 | 109 | "2": [{
|
57 | 110 | "class": "saml2.mdstore.MetaDataFile",
|
58 |
| - "metadata": [(full_path("InCommon-metadata.xml"), )], |
| 111 | + "metadata": [(full_path("InCommon-metadata.xml"),)], |
59 | 112 | }],
|
60 | 113 | "3": [{
|
61 | 114 | "class": "saml2.mdstore.MetaDataFile",
|
62 |
| - "metadata": [(full_path("extended.xml"), )], |
| 115 | + "metadata": [(full_path("extended.xml"),)], |
63 | 116 | }],
|
64 | 117 | # "7": [{
|
65 | 118 | # "class": "saml2.mdstore.MetaDataFile",
|
|
68 | 121 | # {
|
69 | 122 | # "class": "saml2.mdstore.MetaDataExtern",
|
70 | 123 | # "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", |
72 | 126 | # full_path("kalmar2.pem")), ],
|
73 | 127 | # }],
|
74 | 128 | "4": [{
|
75 | 129 | "class": "saml2.mdstore.MetaDataFile",
|
76 |
| - "metadata": [(full_path("metadata_example.xml"), )], |
| 130 | + "metadata": [(full_path("metadata_example.xml"),)], |
77 | 131 | }],
|
78 | 132 | "5": [{
|
79 | 133 | "class": "saml2.mdstore.MetaDataFile",
|
80 |
| - "metadata": [(full_path("metadata.aaitest.xml"), )], |
| 134 | + "metadata": [(full_path("metadata.aaitest.xml"),)], |
81 | 135 | }],
|
82 | 136 | "8": [{
|
83 | 137 | "class": "saml2.mdstore.MetaDataMD",
|
84 |
| - "metadata": [(full_path("swamid.md"), )], |
| 138 | + "metadata": [(full_path("swamid.md"),)], |
85 | 139 | }],
|
86 | 140 | "9": [{
|
87 | 141 | "class": "saml2.mdstore.MetaDataFile",
|
88 |
| - "metadata": [(full_path("metadata"), )] |
| 142 | + "metadata": [(full_path("metadata"),)] |
89 | 143 | }],
|
90 | 144 | "10": [{
|
91 | 145 | "class": "saml2.mdstore.MetaDataExtern",
|
92 | 146 | "metadata": [
|
93 | 147 | ("http://md.incommon.org/InCommon/InCommon-metadata-export.xml",
|
94 | 148 | full_path("inc-md-cert.pem"))]
|
95 |
| - } |
96 |
| - ] |
| 149 | + }], |
| 150 | + "11": [{ |
| 151 | + "class": "saml2.mdstore.InMemoryMetaData", |
| 152 | + "metadata": [(TEST_METADATA_STRING, )] |
| 153 | + }], |
97 | 154 | }
|
98 | 155 |
|
99 | 156 |
|
@@ -295,5 +352,37 @@ def test_load_extern_incommon():
|
295 | 352 | assert mds
|
296 | 353 | assert len(mds.keys())
|
297 | 354 |
|
| 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 | + |
298 | 387 | if __name__ == "__main__":
|
299 |
| - test_load_extern_incommon() |
| 388 | + test_load_string() |
0 commit comments