Skip to content

Commit 5151e4a

Browse files
committed
Set force_authn when the value is "true" or "1"
Following d257d30 the ForceAuthn attribute is an xsd:boolean value which can be any of "false", "true", "0" or "1". We must set force_authn when the value is "true" or "1". We set the value into kwargs, which is then mirrored onto _args, which is merged with args, which is finally given to the saml2.samlp.AuthnRequest class to construct the object. Previously, we set the value into args directly, which would be overwritten by the call to _filter_args. Signed-off-by: Ivan Kanakarakis <[email protected]>
1 parent e4723fb commit 5151e4a

File tree

2 files changed

+39
-16
lines changed

2 files changed

+39
-16
lines changed

src/saml2/client_base.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -371,13 +371,6 @@ def create_authn_request(self, destination, vorg="", scoping=None,
371371
except KeyError:
372372
nsprefix = None
373373

374-
force_authn = (
375-
kwargs.get("force_authn")
376-
or self.config.getattr('force_authn', 'sp')
377-
)
378-
if str(force_authn).lower() == 'true':
379-
args['force_authn'] = 'true'
380-
381374
conf_sp_type = self.config.getattr('sp_type', 'sp')
382375
conf_sp_type_in_md = self.config.getattr('sp_type_in_metadata', 'sp')
383376
if conf_sp_type and conf_sp_type_in_md is False:
@@ -439,9 +432,17 @@ def create_authn_request(self, destination, vorg="", scoping=None,
439432
extension_elements=items)
440433
extensions.add_extension_element(item)
441434

435+
force_authn = str(
436+
kwargs.pop("force_authn", None)
437+
or self.config.getattr("force_authn", "sp")
438+
).lower() in ["true", "1"]
439+
if force_authn:
440+
kwargs["force_authn"] = "true"
441+
442442
if kwargs:
443-
_args, extensions = self._filter_args(AuthnRequest(), extensions,
444-
**kwargs)
443+
_args, extensions = self._filter_args(
444+
AuthnRequest(), extensions, **kwargs
445+
)
445446
args.update(_args)
446447

447448
args.pop("id", None)

tests/test_51_client.py

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -286,16 +286,38 @@ def test_create_auth_request_0(self):
286286
assert c.attributes['FriendlyName']
287287
assert c.attributes['NameFormat']
288288

289-
def test_create_auth_request_unset_force_authn(self):
289+
def test_create_auth_request_unset_force_authn_by_default(self):
290290
req_id, req = self.client.create_authn_request(
291-
"http://www.example.com/sso", sign=False, message_id="id1")
292-
assert bool(req.force_authn) == False
291+
"http://www.example.com/sso", sign=False, message_id="id1"
292+
)
293+
assert req.force_authn is None
293294

294-
def test_create_auth_request_set_force_authn(self):
295+
def test_create_auth_request_set_force_authn_not_true_or_1(self):
295296
req_id, req = self.client.create_authn_request(
296-
"http://www.example.com/sso", sign=False, message_id="id1",
297-
force_authn="true")
298-
assert bool(req.force_authn) == True
297+
"http://www.example.com/sso",
298+
sign=False,
299+
message_id="id1",
300+
force_authn="0",
301+
)
302+
assert req.force_authn is None
303+
304+
def test_create_auth_request_set_force_authn_true(self):
305+
req_id, req = self.client.create_authn_request(
306+
"http://www.example.com/sso",
307+
sign=False,
308+
message_id="id1",
309+
force_authn="true",
310+
)
311+
assert req.force_authn == "true"
312+
313+
def test_create_auth_request_set_force_authn_1(self):
314+
req_id, req = self.client.create_authn_request(
315+
"http://www.example.com/sso",
316+
sign=False,
317+
message_id="id1",
318+
force_authn="true",
319+
)
320+
assert req.force_authn == "true"
299321

300322
def test_create_auth_request_nameid_policy_allow_create(self):
301323
conf = config.SPConfig()

0 commit comments

Comments
 (0)