Skip to content

Commit 9b4822f

Browse files
committed
Merge PR OCA#600 into 15.0
Signed-off-by vincent-hatakeyama
2 parents 668a41e + 26a1baf commit 9b4822f

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

auth_saml/models/ir_config_parameter.py

+10
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,13 @@ def write(self, vals):
2727
if self.filtered(lambda param: param.key == ALLOW_SAML_UID_AND_PASSWORD):
2828
self.env["res.users"].allow_saml_and_password_changed()
2929
return result
30+
31+
def unlink(self):
32+
"""Redefined to update users when our parameter is deleted."""
33+
param_saml = self.filtered(
34+
lambda param: param.key == ALLOW_SAML_UID_AND_PASSWORD
35+
)
36+
result = super().unlink()
37+
if result and param_saml:
38+
self.env["res.users"].allow_saml_and_password_changed()
39+
return result

auth_saml/tests/test_pysaml.py

+24-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ def test_login_with_saml(self):
198198
# User should now be able to log in with the token
199199
self.authenticate(user="test@example.com", password=token)
200200

201-
def test_disallow_user_password_when_changing_setting(self):
201+
def test_disallow_user_password_when_changing_ir_config_parameter(self):
202202
"""Test that disabling users from having both a password and SAML ids remove
203203
users password."""
204204
# change the option
@@ -336,3 +336,26 @@ def test_redirect_after_login(self):
336336
self.base_url()
337337
+ "/web#action=37&model=ir.module.module&view_type=kanban&menu_id=5",
338338
)
339+
340+
def test_disallow_user_password_when_changing_settings(self):
341+
"""Test that disabling the setting will remove passwords from related users"""
342+
# We activate the settings to allow password login
343+
self.env["res.config.settings"].create(
344+
{
345+
"allow_saml_uid_and_internal_password": True,
346+
}
347+
).execute()
348+
349+
# Test the user can login with the password
350+
self.authenticate(user="user@example.com", password="NesTNSte9340D720te>/-A")
351+
352+
self.env["res.config.settings"].create(
353+
{
354+
"allow_saml_uid_and_internal_password": False,
355+
}
356+
).execute()
357+
358+
with self.assertRaises(AccessDenied):
359+
self.authenticate(
360+
user="user@example.com", password="NesTNSte9340D720te>/-A"
361+
)

0 commit comments

Comments
 (0)