Skip to content

Commit e98172b

Browse files
committed
Remove the metadata_construction param
Additionally, the saml2.assertion.Policy object can be initialized with a metadata store and thus the .restrict and .filter methods do not need such a param. This will remain as it was, until some time has passed and confidence is built that peolpe are using a recent enough version of pysaml2, before dropping the param from the .restrict method. Up to that point, warnings will be output, but functionality is preserved. Signed-off-by: Ivan Kanakarakis <[email protected]>
1 parent 8b95e0e commit e98172b

File tree

10 files changed

+32
-30
lines changed

10 files changed

+32
-30
lines changed

src/satosa/backends/saml2.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,7 @@ def __init__(self, outgoing, internal_attributes, config, base_url, name):
104104
super().__init__(outgoing, internal_attributes, base_url, name)
105105
self.config = self.init_config(config)
106106

107-
sp_config = SPConfig().load(copy.deepcopy(
108-
config[SAMLBackend.KEY_SP_CONFIG]), False
109-
)
107+
sp_config = SPConfig().load(copy.deepcopy(config[SAMLBackend.KEY_SP_CONFIG]))
110108
self.sp = Base(sp_config)
111109

112110
self.discosrv = config.get(SAMLBackend.KEY_DISCO_SRV)

src/satosa/frontends/saml2.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def register_endpoints(self, backend_names):
116116
self.idp_config = self._build_idp_config_endpoints(
117117
self.config[self.KEY_IDP_CONFIG], backend_names)
118118
# Create the idp
119-
idp_config = IdPConfig().load(copy.deepcopy(self.idp_config), metadata_construction=False)
119+
idp_config = IdPConfig().load(copy.deepcopy(self.idp_config))
120120
self.idp = Server(config=idp_config)
121121
return self._register_endpoints(backend_names)
122122

@@ -290,9 +290,14 @@ def _filter_attributes(self, idp, internal_response, context,):
290290
idp_policy = idp.config.getattr("policy", "idp")
291291
attributes = {}
292292
if idp_policy:
293-
approved_attributes = self._get_approved_attributes(idp, idp_policy, internal_response.requester,
294-
context.state)
295-
attributes = {k: v for k, v in internal_response.attributes.items() if k in approved_attributes}
293+
approved_attributes = self._get_approved_attributes(
294+
idp, idp_policy, internal_response.requester, context.state
295+
)
296+
attributes = {
297+
k: v
298+
for k, v in internal_response.attributes.items()
299+
if k in approved_attributes
300+
}
296301

297302
return attributes
298303

@@ -637,7 +642,7 @@ def _load_idp_dynamic_endpoints(self, context):
637642
"""
638643
target_entity_id = context.target_entity_id_from_path()
639644
idp_conf_file = self._load_endpoints_to_config(context.target_backend, target_entity_id)
640-
idp_config = IdPConfig().load(idp_conf_file, metadata_construction=False)
645+
idp_config = IdPConfig().load(idp_conf_file)
641646
return Server(config=idp_config)
642647

643648
def _load_idp_dynamic_entity_id(self, state):
@@ -653,7 +658,7 @@ def _load_idp_dynamic_entity_id(self, state):
653658
# Change the idp entity id dynamically
654659
idp_config_file = copy.deepcopy(self.idp_config)
655660
idp_config_file["entityid"] = "{}/{}".format(self.idp_config["entityid"], state[self.name]["target_entity_id"])
656-
idp_config = IdPConfig().load(idp_config_file, metadata_construction=False)
661+
idp_config = IdPConfig().load(idp_config_file)
657662
return Server(config=idp_config)
658663

659664
def handle_authn_request(self, context, binding_in):
@@ -1033,8 +1038,7 @@ def _create_co_virtual_idp(self, context):
10331038

10341039
# Use the overwritten IdP config to generate a pysaml2 config object
10351040
# and from it a server object.
1036-
pysaml2_idp_config = IdPConfig().load(idp_config,
1037-
metadata_construction=False)
1041+
pysaml2_idp_config = IdPConfig().load(idp_config)
10381042

10391043
server = Server(config=pysaml2_idp_config)
10401044

src/satosa/metadata_creation/saml_metadata.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818

1919
def _create_entity_descriptor(entity_config):
20-
cnf = Config().load(copy.deepcopy(entity_config), metadata_construction=True)
20+
cnf = Config().load(copy.deepcopy(entity_config))
2121
return entity_descriptor(cnf)
2222

2323

tests/flows/test_oidc-saml.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def test_full_flow(self, satosa_config_dict, oidc_frontend_config, saml_backend_
7878
# config test IdP
7979
backend_metadata_str = str(backend_metadata[saml_backend_config["name"]][0])
8080
idp_conf["metadata"]["inline"].append(backend_metadata_str)
81-
fakeidp = FakeIdP(USERS, config=IdPConfig().load(idp_conf, metadata_construction=False))
81+
fakeidp = FakeIdP(USERS, config=IdPConfig().load(idp_conf))
8282

8383
# create auth resp
8484
req_params = dict(parse_qsl(urlparse(proxied_auth_req.data.decode("utf-8")).query))

tests/flows/test_saml-oidc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def run_test(self, satosa_config_dict, sp_conf, oidc_backend_config, frontend_co
3232
# config test SP
3333
frontend_metadata_str = str(frontend_metadata[frontend_config["name"]][0])
3434
sp_conf["metadata"]["inline"].append(frontend_metadata_str)
35-
fakesp = FakeSP(SPConfig().load(sp_conf, metadata_construction=False))
35+
fakesp = FakeSP(SPConfig().load(sp_conf))
3636

3737
# create auth req
3838
destination, req_args = fakesp.make_auth_req(frontend_metadata[frontend_config["name"]][0].entity_id)

tests/flows/test_saml-saml.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def run_test(self, satosa_config_dict, sp_conf, idp_conf, saml_backend_config, f
2828
# config test SP
2929
frontend_metadata_str = str(frontend_metadata[frontend_config["name"]][0])
3030
sp_conf["metadata"]["inline"].append(frontend_metadata_str)
31-
fakesp = FakeSP(SPConfig().load(sp_conf, metadata_construction=False))
31+
fakesp = FakeSP(SPConfig().load(sp_conf))
3232

3333
# create auth req
3434
destination, req_args = fakesp.make_auth_req(frontend_metadata[frontend_config["name"]][0].entity_id)
@@ -41,7 +41,7 @@ def run_test(self, satosa_config_dict, sp_conf, idp_conf, saml_backend_config, f
4141
# config test IdP
4242
backend_metadata_str = str(backend_metadata[saml_backend_config["name"]][0])
4343
idp_conf["metadata"]["inline"].append(backend_metadata_str)
44-
fakeidp = FakeIdP(USERS, config=IdPConfig().load(idp_conf, metadata_construction=False))
44+
fakeidp = FakeIdP(USERS, config=IdPConfig().load(idp_conf))
4545

4646
# create auth resp
4747
req_params = dict(parse_qsl(urlparse(proxied_auth_req.data.decode("utf-8")).query))

tests/satosa/backends/test_saml2.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def test_discovery_server_set_in_context(self, context, sp_conf):
118118
def test_full_flow(self, context, idp_conf, sp_conf):
119119
test_state_key = "test_state_key_456afgrh"
120120
response_binding = BINDING_HTTP_REDIRECT
121-
fakeidp = FakeIdP(USERS, config=IdPConfig().load(idp_conf, metadata_construction=False))
121+
fakeidp = FakeIdP(USERS, config=IdPConfig().load(idp_conf))
122122

123123
context.state[test_state_key] = "my_state"
124124

@@ -181,8 +181,8 @@ def test_authn_request(self, context, idp_conf):
181181

182182
def test_authn_response(self, context, idp_conf, sp_conf):
183183
response_binding = BINDING_HTTP_REDIRECT
184-
fakesp = FakeSP(SPConfig().load(sp_conf, metadata_construction=False))
185-
fakeidp = FakeIdP(USERS, config=IdPConfig().load(idp_conf, metadata_construction=False))
184+
fakesp = FakeSP(SPConfig().load(sp_conf))
185+
fakeidp = FakeIdP(USERS, config=IdPConfig().load(idp_conf))
186186
destination, request_params = fakesp.make_auth_req(idp_conf["entityid"])
187187
url, auth_resp = fakeidp.handle_auth_req(request_params["SAMLRequest"], request_params["RelayState"],
188188
BINDING_HTTP_REDIRECT,
@@ -202,10 +202,10 @@ def test_authn_response(self, context, idp_conf, sp_conf):
202202
def test_authn_response_no_name_id(self, context, idp_conf, sp_conf):
203203
response_binding = BINDING_HTTP_REDIRECT
204204

205-
fakesp_conf = SPConfig().load(sp_conf, metadata_construction=False)
205+
fakesp_conf = SPConfig().load(sp_conf)
206206
fakesp = FakeSP(fakesp_conf)
207207

208-
fakeidp_conf = IdPConfig().load(idp_conf, metadata_construction=False)
208+
fakeidp_conf = IdPConfig().load(idp_conf)
209209
fakeidp = FakeIdP(USERS, config=fakeidp_conf)
210210

211211
destination, request_params = fakesp.make_auth_req(

tests/satosa/frontends/test_saml2.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def setup_for_authn_req(self, context, idp_conf, sp_conf, nameid_format=None, re
7575
idp_metadata_str = create_metadata_from_config_dict(samlfrontend.idp_config)
7676
sp_conf["metadata"]["inline"].append(idp_metadata_str)
7777

78-
fakesp = FakeSP(SPConfig().load(sp_conf, metadata_construction=False))
78+
fakesp = FakeSP(SPConfig().load(sp_conf))
7979
destination, auth_req = fakesp.make_auth_req(
8080
samlfrontend.idp_config["entityid"],
8181
nameid_format,
@@ -94,7 +94,7 @@ def setup_for_authn_req(self, context, idp_conf, sp_conf, nameid_format=None, re
9494
return samlfrontend
9595

9696
def get_auth_response(self, samlfrontend, context, internal_response, sp_conf, idp_metadata_str):
97-
sp_config = SPConfig().load(sp_conf, metadata_construction=False)
97+
sp_config = SPConfig().load(sp_conf)
9898
resp_args = {
9999
"name_id_policy": NameIDPolicy(format=NAMEID_FORMAT_TRANSIENT),
100100
"in_response_to": None,
@@ -150,7 +150,7 @@ def test_handle_authn_request(self, context, idp_conf, sp_conf, internal_respons
150150
resp = samlfrontend.handle_authn_response(context, internal_response)
151151
resp_dict = parse_qs(urlparse(resp.message).query)
152152

153-
fakesp = FakeSP(SPConfig().load(sp_conf, metadata_construction=False))
153+
fakesp = FakeSP(SPConfig().load(sp_conf))
154154
resp = fakesp.parse_authn_request_response(resp_dict["SAMLResponse"][0],
155155
BINDING_HTTP_REDIRECT)
156156
for key in resp.ava:
@@ -189,7 +189,7 @@ def test_handle_authn_response_without_relay_state(self, context, idp_conf, sp_c
189189
resp = samlfrontend.handle_authn_response(context, internal_response)
190190
resp_dict = parse_qs(urlparse(resp.message).query)
191191

192-
fakesp = FakeSP(SPConfig().load(sp_conf, metadata_construction=False))
192+
fakesp = FakeSP(SPConfig().load(sp_conf))
193193
resp = fakesp.parse_authn_request_response(resp_dict["SAMLResponse"][0],
194194
BINDING_HTTP_REDIRECT)
195195

@@ -213,7 +213,7 @@ def test_handle_authn_response_without_name_id(
213213
resp = samlfrontend.handle_authn_response(context, internal_response)
214214
resp_dict = parse_qs(urlparse(resp.message).query)
215215

216-
fakesp = FakeSP(SPConfig().load(sp_conf, metadata_construction=False))
216+
fakesp = FakeSP(SPConfig().load(sp_conf))
217217
resp = fakesp.parse_authn_request_response(
218218
resp_dict["SAMLResponse"][0], BINDING_HTTP_REDIRECT)
219219

@@ -548,7 +548,7 @@ def test_co_static_attributes(self, frontend, context, internal_response,
548548
# SP configuration fixture with the metadata.
549549
idp_metadata_str = create_metadata_from_config_dict(idp_conf)
550550
sp_conf["metadata"]["inline"].append(idp_metadata_str)
551-
sp_config = SPConfig().load(sp_conf, metadata_construction=False)
551+
sp_config = SPConfig().load(sp_conf)
552552

553553
# Use the updated sp_config fixture to generate a fake SP and then
554554
# use the fake SP to generate an authentication request aimed at the

tests/satosa/metadata_creation/test_saml_metadata.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ def test_create_mirrored_metadata_does_not_contain_target_contact_info(self, sat
236236
class TestCreateSignedEntitiesDescriptor:
237237
@pytest.fixture
238238
def entity_desc(self, sp_conf):
239-
return entity_descriptor(SPConfig().load(sp_conf, metadata_construction=True))
239+
return entity_descriptor(SPConfig().load(sp_conf))
240240

241241
@pytest.fixture
242242
def verification_security_context(self, cert_and_key):
@@ -274,7 +274,7 @@ def test_valid_for(self, entity_desc, signature_security_context):
274274
class TestCreateSignedEntityDescriptor:
275275
@pytest.fixture
276276
def entity_desc(self, sp_conf):
277-
return entity_descriptor(SPConfig().load(sp_conf, metadata_construction=True))
277+
return entity_descriptor(SPConfig().load(sp_conf))
278278

279279
@pytest.fixture
280280
def verification_security_context(self, cert_and_key):

tests/util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ def handle_auth_req_no_name_id(self, saml_request, relay_state, binding,
231231

232232
def create_metadata_from_config_dict(config):
233233
nspair = {"xs": "http://www.w3.org/2001/XMLSchema"}
234-
conf = Config().load(config, metadata_construction=True)
234+
conf = Config().load(config)
235235
return entity_descriptor(conf).to_string(nspair).decode("utf-8")
236236

237237

0 commit comments

Comments
 (0)