You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
2.3 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright (C) 2013-2014 GRAP (http://www.grap.coop)
  3. # @author Sylvain LE GAL (https://twitter.com/legalsylvain)
  4. # License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
  5. from odoo import SUPERUSER_ID, exceptions
  6. from odoo.tests import common
  7. @common.post_install(True)
  8. class TestAuthAdminPasskey(common.TransactionCase):
  9. """Tests for 'Auth Admin Passkey' Module"""
  10. def setUp(self):
  11. super(TestAuthAdminPasskey, self).setUp()
  12. self.ru_obj = self.env['res.users']
  13. self.db = self.env.cr.dbname
  14. self.admin_user = self.ru_obj.search([('id', '=', SUPERUSER_ID)])
  15. self.passkey_user = self.ru_obj.create({
  16. 'login': 'passkey',
  17. 'password': 'PasskeyPa$$w0rd',
  18. 'name': 'passkey'
  19. })
  20. def test_01_normal_login_admin_succeed(self):
  21. # NOTE: Can fail if admin password changed
  22. self.admin_user.check_credentials('admin')
  23. def test_02_normal_login_admin_fail(self):
  24. with self.assertRaises(exceptions.AccessDenied):
  25. self.admin_user.check_credentials('bad_password')
  26. def test_03_normal_login_passkey_succeed(self):
  27. """ This test cannot pass because in some way the the _uid of
  28. passkey_user is equal to admin one so when entering the
  29. original check_credentials() method, it raises an exception
  30. """
  31. try:
  32. self.passkey_user.check_credentials('passkey')
  33. except exceptions.AccessDenied:
  34. # This exception is raised from the origin check_credentials()
  35. # method and its an expected behaviour as we catch this in our
  36. # check_credentials()
  37. pass
  38. def test_04_normal_login_passkey_fail(self):
  39. with self.assertRaises(exceptions.AccessDenied):
  40. self.passkey_user.check_credentials('bad_password')
  41. def test_05_passkey_login_passkey_with_admin_password_succeed(self):
  42. # NOTE: Can fail if admin password changed
  43. self.passkey_user.check_credentials('admin')
  44. def test_06_passkey_login_passkey_succeed(self):
  45. """[Bug #1319391]
  46. Test the correct behaviour of login with 'bad_login' / 'admin'"""
  47. res = self.ru_obj.authenticate(self.db, 'bad_login', 'admin', {})
  48. self.assertFalse(res)