Skip to content

Commit 2641019

Browse files
committed
Remove the metadata_construction param
Signed-off-by: Ivan Kanakarakis <[email protected]>
1 parent 915add3 commit 2641019

File tree

6 files changed

+51
-35
lines changed

6 files changed

+51
-35
lines changed

src/saml2/config.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -272,15 +272,22 @@ def load_complex(self, cnf):
272272
policy_conf = spec.get("policy")
273273
self.setattr(srv, "policy", Policy(policy_conf, self.metadata))
274274

275-
def load(self, cnf, metadata_construction=False):
275+
def load(self, cnf, metadata_construction=None):
276276
""" The base load method, loads the configuration
277277
278278
:param cnf: The configuration as a dictionary
279-
:param metadata_construction: Is this only to be able to construct
280-
metadata. If so some things can be left out.
281279
:return: The Configuration instance
282280
"""
283281

282+
if metadata_construction is not None:
283+
warn_msg = (
284+
"The metadata_construction parameter for saml2.config.Config.load "
285+
"is deprecated and ignored; "
286+
"instead, initialize the Policy object setting the mds param."
287+
)
288+
logger.warning(warn_msg)
289+
_warn(warn_msg, DeprecationWarning)
290+
284291
for arg in COMMON_ARGS:
285292
if arg == "virtual_organization":
286293
if "virtual_organization" in cnf:
@@ -338,12 +345,21 @@ def _load(self, fil):
338345

339346
return importlib.import_module(tail)
340347

341-
def load_file(self, config_filename, metadata_construction=False):
348+
def load_file(self, config_filename, metadata_construction=None):
349+
if metadata_construction is not None:
350+
warn_msg = (
351+
"The metadata_construction parameter for saml2.config.Config.load_file "
352+
"is deprecated and ignored; "
353+
"instead, initialize the Policy object setting the mds param."
354+
)
355+
logger.warning(warn_msg)
356+
_warn(warn_msg, DeprecationWarning)
357+
342358
if config_filename.endswith(".py"):
343359
config_filename = config_filename[:-3]
344360

345361
mod = self._load(config_filename)
346-
return self.load(copy.deepcopy(mod.CONFIG), metadata_construction)
362+
return self.load(copy.deepcopy(mod.CONFIG))
347363

348364
def load_metadata(self, metadata_conf):
349365
""" Loads metadata into an internal structure """

src/saml2/metadata.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def create_metadata_string(configfile, config=None, valid=None, cert=None,
8989
if config is None:
9090
if configfile.endswith(".py"):
9191
configfile = configfile[:-3]
92-
config = Config().load_file(configfile, metadata_construction=True)
92+
config = Config().load_file(configfile)
9393
eds.append(entity_descriptor(config))
9494

9595
conf = Config()

tests/otest_61_makemeta.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def test_org_3():
116116
org = metadata.do_organization_info(desc)
117117
assert _eq(org.keyswv(), ['organization_display_name'])
118118
assert len(org.organization_display_name) == 1
119-
119+
120120
def test_contact_0():
121121
conf = [{
122122
"given_name":"Roland",
@@ -126,7 +126,7 @@ def test_contact_0():
126126
"contact_type": "technical"
127127
}]
128128
contact_person = metadata.do_contact_person_info(conf)
129-
assert _eq(contact_person[0].keyswv(), ['given_name', 'sur_name',
129+
assert _eq(contact_person[0].keyswv(), ['given_name', 'sur_name',
130130
'contact_type', 'telephone_number',
131131
"email_address"])
132132
print(contact_person[0])
@@ -141,27 +141,27 @@ def test_contact_0():
141141
assert len(person.email_address) == 2
142142
assert isinstance(person.email_address[0], md.EmailAddress)
143143
assert person.email_address[0].text == "[email protected]"
144-
144+
145145
def test_do_endpoints():
146146
eps = metadata.do_endpoints(SP["service"]["sp"]["endpoints"],
147147
metadata.ENDPOINTS["sp"])
148148
print(eps)
149-
assert _eq(eps.keys(), ["assertion_consumer_service",
149+
assert _eq(eps.keys(), ["assertion_consumer_service",
150150
"single_logout_service"])
151-
151+
152152
assert len(eps["single_logout_service"]) == 1
153153
sls = eps["single_logout_service"][0]
154154
assert sls.location == "http://localhost:8087/logout"
155155
assert sls.binding == BINDING_HTTP_POST
156-
156+
157157
assert len(eps["assertion_consumer_service"]) == 1
158158
acs = eps["assertion_consumer_service"][0]
159159
assert acs.location == "http://localhost:8087/"
160160
assert acs.binding == BINDING_HTTP_POST
161-
161+
162162
assert "artifact_resolution_service" not in eps
163163
assert "manage_name_id_service" not in eps
164-
164+
165165
def test_required_attributes():
166166
attrconverters = ac_factory("../tests/attributemaps")
167167
ras = metadata.do_requested_attribute(
@@ -183,19 +183,19 @@ def test_optional_attributes():
183183
assert ras[0].name == 'urn:oid:2.5.4.12'
184184
assert ras[0].name_format == NAME_FORMAT_URI
185185
assert ras[0].is_required == "false"
186-
186+
187187
def test_do_sp_sso_descriptor():
188-
conf = SPConfig().load(SP, metadata_construction=True)
188+
conf = SPConfig().load(SP)
189189
spsso = metadata.do_spsso_descriptor(conf)
190-
190+
191191
assert isinstance(spsso, md.SPSSODescriptor)
192-
assert _eq(spsso.keyswv(), ['authn_requests_signed',
193-
'attribute_consuming_service',
194-
'single_logout_service',
195-
'protocol_support_enumeration',
196-
'assertion_consumer_service',
192+
assert _eq(spsso.keyswv(), ['authn_requests_signed',
193+
'attribute_consuming_service',
194+
'single_logout_service',
195+
'protocol_support_enumeration',
196+
'assertion_consumer_service',
197197
'want_assertions_signed'])
198-
198+
199199
assert spsso.authn_requests_signed == "false"
200200
assert spsso.want_assertions_signed == "true"
201201
assert len (spsso.attribute_consuming_service) == 1
@@ -213,8 +213,8 @@ def test_do_sp_sso_descriptor():
213213

214214
def test_do_sp_sso_descriptor_2():
215215
SP["service"]["sp"]["discovery_response"] = "http://example.com/sp/ds"
216-
217-
conf = SPConfig().load(SP, metadata_construction=True)
216+
217+
conf = SPConfig().load(SP)
218218
spsso = metadata.do_spsso_descriptor(conf)
219219

220220
assert isinstance(spsso, md.SPSSODescriptor)
@@ -251,12 +251,12 @@ def test_entity_description():
251251
assert entd.entity_id == "urn:mace:example.com:saml:roland:sp"
252252

253253
def test_do_idp_sso_descriptor():
254-
conf = IdPConfig().load(IDP, metadata_construction=True)
254+
conf = IdPConfig().load(IDP)
255255
idpsso = metadata.do_idpsso_descriptor(conf)
256256

257257
assert isinstance(idpsso, md.IDPSSODescriptor)
258-
assert _eq(idpsso.keyswv(), ['protocol_support_enumeration',
259-
'single_sign_on_service',
258+
assert _eq(idpsso.keyswv(), ['protocol_support_enumeration',
259+
'single_sign_on_service',
260260
'want_authn_requests_signed',
261261
"extensions"])
262262
exts = idpsso.extensions.extension_elements

tests/test_39_metadata.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131

3232
def test_requested_attribute_name_format():
33-
cnf = SPConfig().load(sp_conf, metadata_construction=True)
33+
cnf = SPConfig().load(sp_conf)
3434
ed = entity_descriptor(cnf)
3535

3636
assert len(ed.spsso_descriptor.attribute_consuming_service) == 1
@@ -42,7 +42,7 @@ def test_requested_attribute_name_format():
4242
sp2 = copy.copy(sp_conf)
4343
sp2["service"]["sp"]["requested_attribute_name_format"] = NAME_FORMAT_BASIC
4444

45-
cnf2 = SPConfig().load(sp2, metadata_construction=True)
45+
cnf2 = SPConfig().load(sp2)
4646
ed = entity_descriptor(cnf2)
4747
acs = ed.spsso_descriptor.attribute_consuming_service[0]
4848
assert len(acs.requested_attribute) == 4
@@ -56,7 +56,7 @@ def test_signed_metadata_proper_str_bytes_handling():
5656
sp_conf_2['cert_file'] = full_path("inc-md-cert.pem")
5757
# requires xmlsec binaries per https://pysaml2.readthedocs.io/en/latest/examples/sp.html
5858
sp_conf_2['xmlsec_binary'] = sigver.get_xmlsec_binary(["/opt/local/bin"])
59-
cnf = SPConfig().load(sp_conf_2, metadata_construction=True)
59+
cnf = SPConfig().load(sp_conf_2)
6060

6161
# This will raise TypeError if string/bytes handling is not correct
6262
sp_metadata = create_metadata_string('', config=cnf, sign=True)

tests/test_83_md_extensions.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
class TestMDExt():
1010
def test_sp_type_true(self):
1111
fil = "sp_mdext_conf.py"
12-
cnf = Config().load_file(fil, metadata_construction=True)
12+
cnf = Config().load_file(fil)
1313
ed = entity_descriptor(cnf)
1414

1515
assert ed.spsso_descriptor.extensions
@@ -20,15 +20,15 @@ def test_sp_type_true(self):
2020

2121
def test_sp_type_false(self):
2222
fil = "sp_mdext_conf.py"
23-
cnf = Config().load_file(fil, metadata_construction=True)
23+
cnf = Config().load_file(fil)
2424
cnf.setattr('sp', 'sp_type_in_metadata', False)
2525
ed = entity_descriptor(cnf)
2626

2727
assert all(e.tag is not SPType.c_tag for e in ed.extensions.extension_elements)
2828

2929
def test_entity_attributes(self):
3030
fil = "sp_mdext_conf.py"
31-
cnf = Config().load_file(fil, metadata_construction=True)
31+
cnf = Config().load_file(fil)
3232
ed = entity_descriptor(cnf)
3333

3434
entity_attributes = next(

tools/make_metadata.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
sys.path.insert(0, bas)
5454
if fil.endswith(".py"):
5555
fil = fil[:-3]
56-
cnf = Config().load_file(fil, metadata_construction=True)
56+
cnf = Config().load_file(fil)
5757
if valid_for:
5858
cnf.valid_for = valid_for
5959
eds.append(entity_descriptor(cnf))

0 commit comments

Comments
 (0)