diff options
author | Ivan Kanakarakis <ivan.kanak@gmail.com> | 2020-10-30 13:01:03 +0200 |
---|---|---|
committer | Ivan Kanakarakis <ivan.kanak@gmail.com> | 2020-10-30 17:24:04 +0200 |
commit | 264101909354707f613c3ecc2d8d0ad0ddb7fa77 (patch) | |
tree | 3ccc40a56e5ace562257d70002b7f88dab26b902 | |
parent | 915add35f4ae41c513534bdc5e159872cf2f1ff6 (diff) | |
download | pysaml2-264101909354707f613c3ecc2d8d0ad0ddb7fa77.tar.gz |
Remove the metadata_construction param
Signed-off-by: Ivan Kanakarakis <ivan.kanak@gmail.com>
-rw-r--r-- | src/saml2/config.py | 26 | ||||
-rw-r--r-- | src/saml2/metadata.py | 2 | ||||
-rw-r--r-- | tests/otest_61_makemeta.py | 44 | ||||
-rw-r--r-- | tests/test_39_metadata.py | 6 | ||||
-rw-r--r-- | tests/test_83_md_extensions.py | 6 | ||||
-rwxr-xr-x | tools/make_metadata.py | 2 |
6 files changed, 51 insertions, 35 deletions
diff --git a/src/saml2/config.py b/src/saml2/config.py index fb35ebaa..f28d7748 100644 --- a/src/saml2/config.py +++ b/src/saml2/config.py @@ -272,15 +272,22 @@ class Config(object): policy_conf = spec.get("policy") self.setattr(srv, "policy", Policy(policy_conf, self.metadata)) - def load(self, cnf, metadata_construction=False): + def load(self, cnf, metadata_construction=None): """ The base load method, loads the configuration :param cnf: The configuration as a dictionary - :param metadata_construction: Is this only to be able to construct - metadata. If so some things can be left out. :return: The Configuration instance """ + if metadata_construction is not None: + warn_msg = ( + "The metadata_construction parameter for saml2.config.Config.load " + "is deprecated and ignored; " + "instead, initialize the Policy object setting the mds param." + ) + logger.warning(warn_msg) + _warn(warn_msg, DeprecationWarning) + for arg in COMMON_ARGS: if arg == "virtual_organization": if "virtual_organization" in cnf: @@ -338,12 +345,21 @@ class Config(object): return importlib.import_module(tail) - def load_file(self, config_filename, metadata_construction=False): + def load_file(self, config_filename, metadata_construction=None): + if metadata_construction is not None: + warn_msg = ( + "The metadata_construction parameter for saml2.config.Config.load_file " + "is deprecated and ignored; " + "instead, initialize the Policy object setting the mds param." + ) + logger.warning(warn_msg) + _warn(warn_msg, DeprecationWarning) + if config_filename.endswith(".py"): config_filename = config_filename[:-3] mod = self._load(config_filename) - return self.load(copy.deepcopy(mod.CONFIG), metadata_construction) + return self.load(copy.deepcopy(mod.CONFIG)) def load_metadata(self, metadata_conf): """ Loads metadata into an internal structure """ diff --git a/src/saml2/metadata.py b/src/saml2/metadata.py index 50b4ff71..e7ab6011 100644 --- a/src/saml2/metadata.py +++ b/src/saml2/metadata.py @@ -89,7 +89,7 @@ def create_metadata_string(configfile, config=None, valid=None, cert=None, if config is None: if configfile.endswith(".py"): configfile = configfile[:-3] - config = Config().load_file(configfile, metadata_construction=True) + config = Config().load_file(configfile) eds.append(entity_descriptor(config)) conf = Config() diff --git a/tests/otest_61_makemeta.py b/tests/otest_61_makemeta.py index 321d8b38..ba6fb0dc 100644 --- a/tests/otest_61_makemeta.py +++ b/tests/otest_61_makemeta.py @@ -116,7 +116,7 @@ def test_org_3(): org = metadata.do_organization_info(desc) assert _eq(org.keyswv(), ['organization_display_name']) assert len(org.organization_display_name) == 1 - + def test_contact_0(): conf = [{ "given_name":"Roland", @@ -126,7 +126,7 @@ def test_contact_0(): "contact_type": "technical" }] contact_person = metadata.do_contact_person_info(conf) - assert _eq(contact_person[0].keyswv(), ['given_name', 'sur_name', + assert _eq(contact_person[0].keyswv(), ['given_name', 'sur_name', 'contact_type', 'telephone_number', "email_address"]) print(contact_person[0]) @@ -141,27 +141,27 @@ def test_contact_0(): assert len(person.email_address) == 2 assert isinstance(person.email_address[0], md.EmailAddress) assert person.email_address[0].text == "foo@eample.com" - + def test_do_endpoints(): eps = metadata.do_endpoints(SP["service"]["sp"]["endpoints"], metadata.ENDPOINTS["sp"]) print(eps) - assert _eq(eps.keys(), ["assertion_consumer_service", + assert _eq(eps.keys(), ["assertion_consumer_service", "single_logout_service"]) - + assert len(eps["single_logout_service"]) == 1 sls = eps["single_logout_service"][0] assert sls.location == "http://localhost:8087/logout" assert sls.binding == BINDING_HTTP_POST - + assert len(eps["assertion_consumer_service"]) == 1 acs = eps["assertion_consumer_service"][0] assert acs.location == "http://localhost:8087/" assert acs.binding == BINDING_HTTP_POST - + assert "artifact_resolution_service" not in eps assert "manage_name_id_service" not in eps - + def test_required_attributes(): attrconverters = ac_factory("../tests/attributemaps") ras = metadata.do_requested_attribute( @@ -183,19 +183,19 @@ def test_optional_attributes(): assert ras[0].name == 'urn:oid:2.5.4.12' assert ras[0].name_format == NAME_FORMAT_URI assert ras[0].is_required == "false" - + def test_do_sp_sso_descriptor(): - conf = SPConfig().load(SP, metadata_construction=True) + conf = SPConfig().load(SP) spsso = metadata.do_spsso_descriptor(conf) - + assert isinstance(spsso, md.SPSSODescriptor) - assert _eq(spsso.keyswv(), ['authn_requests_signed', - 'attribute_consuming_service', - 'single_logout_service', - 'protocol_support_enumeration', - 'assertion_consumer_service', + assert _eq(spsso.keyswv(), ['authn_requests_signed', + 'attribute_consuming_service', + 'single_logout_service', + 'protocol_support_enumeration', + 'assertion_consumer_service', 'want_assertions_signed']) - + assert spsso.authn_requests_signed == "false" assert spsso.want_assertions_signed == "true" assert len (spsso.attribute_consuming_service) == 1 @@ -213,8 +213,8 @@ def test_do_sp_sso_descriptor(): def test_do_sp_sso_descriptor_2(): SP["service"]["sp"]["discovery_response"] = "http://example.com/sp/ds" - - conf = SPConfig().load(SP, metadata_construction=True) + + conf = SPConfig().load(SP) spsso = metadata.do_spsso_descriptor(conf) assert isinstance(spsso, md.SPSSODescriptor) @@ -251,12 +251,12 @@ def test_entity_description(): assert entd.entity_id == "urn:mace:example.com:saml:roland:sp" def test_do_idp_sso_descriptor(): - conf = IdPConfig().load(IDP, metadata_construction=True) + conf = IdPConfig().load(IDP) idpsso = metadata.do_idpsso_descriptor(conf) assert isinstance(idpsso, md.IDPSSODescriptor) - assert _eq(idpsso.keyswv(), ['protocol_support_enumeration', - 'single_sign_on_service', + assert _eq(idpsso.keyswv(), ['protocol_support_enumeration', + 'single_sign_on_service', 'want_authn_requests_signed', "extensions"]) exts = idpsso.extensions.extension_elements diff --git a/tests/test_39_metadata.py b/tests/test_39_metadata.py index 8ab6dfa5..06de507a 100644 --- a/tests/test_39_metadata.py +++ b/tests/test_39_metadata.py @@ -30,7 +30,7 @@ sp_conf = { def test_requested_attribute_name_format(): - cnf = SPConfig().load(sp_conf, metadata_construction=True) + cnf = SPConfig().load(sp_conf) ed = entity_descriptor(cnf) assert len(ed.spsso_descriptor.attribute_consuming_service) == 1 @@ -42,7 +42,7 @@ def test_requested_attribute_name_format(): sp2 = copy.copy(sp_conf) sp2["service"]["sp"]["requested_attribute_name_format"] = NAME_FORMAT_BASIC - cnf2 = SPConfig().load(sp2, metadata_construction=True) + cnf2 = SPConfig().load(sp2) ed = entity_descriptor(cnf2) acs = ed.spsso_descriptor.attribute_consuming_service[0] assert len(acs.requested_attribute) == 4 @@ -56,7 +56,7 @@ def test_signed_metadata_proper_str_bytes_handling(): sp_conf_2['cert_file'] = full_path("inc-md-cert.pem") # requires xmlsec binaries per https://pysaml2.readthedocs.io/en/latest/examples/sp.html sp_conf_2['xmlsec_binary'] = sigver.get_xmlsec_binary(["/opt/local/bin"]) - cnf = SPConfig().load(sp_conf_2, metadata_construction=True) + cnf = SPConfig().load(sp_conf_2) # This will raise TypeError if string/bytes handling is not correct sp_metadata = create_metadata_string('', config=cnf, sign=True) diff --git a/tests/test_83_md_extensions.py b/tests/test_83_md_extensions.py index 35098595..df2c9125 100644 --- a/tests/test_83_md_extensions.py +++ b/tests/test_83_md_extensions.py @@ -9,7 +9,7 @@ from saml2.metadata import entity_descriptor class TestMDExt(): def test_sp_type_true(self): fil = "sp_mdext_conf.py" - cnf = Config().load_file(fil, metadata_construction=True) + cnf = Config().load_file(fil) ed = entity_descriptor(cnf) assert ed.spsso_descriptor.extensions @@ -20,7 +20,7 @@ class TestMDExt(): def test_sp_type_false(self): fil = "sp_mdext_conf.py" - cnf = Config().load_file(fil, metadata_construction=True) + cnf = Config().load_file(fil) cnf.setattr('sp', 'sp_type_in_metadata', False) ed = entity_descriptor(cnf) @@ -28,7 +28,7 @@ class TestMDExt(): def test_entity_attributes(self): fil = "sp_mdext_conf.py" - cnf = Config().load_file(fil, metadata_construction=True) + cnf = Config().load_file(fil) ed = entity_descriptor(cnf) entity_attributes = next( diff --git a/tools/make_metadata.py b/tools/make_metadata.py index f2ae4476..147425fe 100755 --- a/tools/make_metadata.py +++ b/tools/make_metadata.py @@ -53,7 +53,7 @@ for filespec in args.config: sys.path.insert(0, bas) if fil.endswith(".py"): fil = fil[:-3] - cnf = Config().load_file(fil, metadata_construction=True) + cnf = Config().load_file(fil) if valid_for: cnf.valid_for = valid_for eds.append(entity_descriptor(cnf)) |