-
-
Notifications
You must be signed in to change notification settings - Fork 438
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[18.0][MIG] auth_admin_passkey: Migration to 18.0
- Loading branch information
Showing
3 changed files
with
86 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,35 +43,106 @@ def setUpClass(cls): | |
cls.user = user.with_user(user) | ||
|
||
def test_01_normal_login_succeed(self): | ||
self.user._check_credentials(self.user_password, {"interactive": True}) | ||
self.user._check_credentials( | ||
{"type": "password", "password": self.user_password}, | ||
{"interactive": True}, | ||
) | ||
|
||
def test_02_normal_login_fail(self): | ||
with self.assertRaises(exceptions.AccessDenied): | ||
self.user._check_credentials(self.bad_password, {"interactive": True}) | ||
self.user._check_credentials( | ||
{"type": "password", "password": self.bad_password}, | ||
{"interactive": True}, | ||
) | ||
|
||
def test_03_normal_login_passkey_fail(self): | ||
# This should failed, because feature is disabled | ||
config["auth_admin_passkey_password"] = False | ||
config["auth_admin_passkey_password_sha512_encrypted"] = False | ||
with self.assertRaises(exceptions.AccessDenied): | ||
self.user._check_credentials(self.sysadmin_passkey, {"interactive": True}) | ||
self.user._check_credentials( | ||
{"type": "password", "password": self.sysadmin_passkey}, | ||
{"interactive": True}, | ||
) | ||
|
||
def test_04_normal_login_passkey_succeed(self): | ||
# This should succeed, because feature is enabled | ||
config["auth_admin_passkey_password"] = self.sysadmin_passkey | ||
config["auth_admin_passkey_password_sha512_encrypted"] = False | ||
self.user._check_credentials(self.sysadmin_passkey, {"interactive": True}) | ||
self.user._check_credentials( | ||
{"type": "password", "password": self.sysadmin_passkey}, | ||
{"interactive": True}, | ||
) | ||
|
||
def test_05_passkey_login_passkey_succeed(self): | ||
"""[Bug #1319391] | ||
Test the correct behaviour of login with 'bad_login' / 'admin'""" | ||
with self.assertRaises(exceptions.AccessDenied): | ||
self.ResUsers.authenticate( | ||
self.db, self.bad_login, self.sysadmin_passkey, {} | ||
self.db, | ||
{ | ||
"login": self.bad_login, | ||
"password": self.sysadmin_passkey, | ||
"type": "password", | ||
}, | ||
{}, | ||
) | ||
|
||
def test_06_normal_login_passkey_succeed_encrypted_password(self): | ||
# This should succeed, because feature is enabled | ||
config["auth_admin_passkey_password"] = self.sysadmin_passkey_encrypted | ||
config["auth_admin_passkey_password_sha512_encrypted"] = True | ||
self.user._check_credentials(self.sysadmin_passkey, {"interactive": True}) | ||
self.user._check_credentials( | ||
{"type": "password", "password": self.sysadmin_passkey}, | ||
{"interactive": True}, | ||
) | ||
|
||
def test_07_email_notification_logic(self): | ||
"""Test that the email notification logic works correctly.""" | ||
config["auth_admin_passkey_sysadmin_email"] = "[email protected]" | ||
config["auth_admin_passkey_send_to_user"] = True | ||
self.user.email = "[email protected]" | ||
|
||
with self.env.cr.savepoint(): | ||
self.user._send_email_passkey(self.user) | ||
mail_ids = self.env["mail.mail"].search( | ||
[("email_to", "in", ["[email protected]", "[email protected]"])] | ||
) | ||
self.assertEqual(len(mail_ids), 2, "Emails should be sent to both admin and user.") | ||
for mail in mail_ids: | ||
self.assertIn("Passkey used", mail.subject) | ||
|
||
def test_08_missing_sysadmin_passkey(self): | ||
"""Test behavior when no passkey is configured.""" | ||
config["auth_admin_passkey_password"] = False | ||
with self.assertRaises(exceptions.AccessDenied): | ||
self.user._check_credentials( | ||
{"type": "password", "password": self.sysadmin_passkey}, | ||
{"interactive": True}, | ||
) | ||
|
||
def test_09_empty_passkey_fails(self): | ||
"""Test behavior when an empty passkey is provided.""" | ||
config["auth_admin_passkey_password"] = self.sysadmin_passkey | ||
with self.assertRaises(exceptions.AccessDenied): | ||
self.user._check_credentials( | ||
{"type": "password", "password": ""}, | ||
{"interactive": True}, | ||
) | ||
|
||
def test_10_prepare_email_passkey(self): | ||
"""Test email preparation logic.""" | ||
subject, body_html = self.user._prepare_email_passkey(self.user) | ||
self.assertIn("Passkey used", subject) | ||
self.assertIn(self.user.login, body_html) | ||
self.assertIn("Login date", body_html) | ||
|
||
def test_11_incorrect_encrypted_password(self): | ||
"""Test login fails with incorrect encrypted password.""" | ||
config["auth_admin_passkey_password"] = self.sysadmin_passkey_encrypted | ||
config["auth_admin_passkey_password_sha512_encrypted"] = True | ||
with self.assertRaises(exceptions.AccessDenied): | ||
self.user._check_credentials( | ||
{"type": "password", "password": "WrongEncryptedPassword"}, | ||
{"interactive": True}, | ||
) |