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.

99 lines
3.7 KiB

  1. # -*- encoding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # Admin Passkey module for Odoo
  5. # Copyright (C) 2013-2014 GRAP (http://www.grap.coop)
  6. # @author Sylvain LE GAL (https://twitter.com/legalsylvain)
  7. #
  8. # This program is free software: you can redistribute it and/or modify
  9. # it under the terms of the GNU Affero General Public License as
  10. # published by the Free Software Foundation, either version 3 of the
  11. # License, or (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU Affero General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU Affero General Public License
  19. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. #
  21. ##############################################################################
  22. import threading
  23. from openerp.tests.common import TransactionCase
  24. class TestAuthAdminPasskey(TransactionCase):
  25. """Tests for 'Auth Admin Passkey' Module"""
  26. # Overload Section
  27. def setUp(self):
  28. super(TestAuthAdminPasskey, self).setUp()
  29. # Get Registries
  30. self.imd_obj = self.registry('ir.model.data')
  31. self.ru_obj = self.registry('res.users')
  32. # Get Database name
  33. self.db = threading.current_thread().dbname
  34. # Get ids from xml_ids
  35. self.admin_user_id = self.imd_obj.get_object_reference(
  36. self.cr, self.uid, 'base', 'user_root')[1]
  37. self.demo_user_id = self.imd_obj.get_object_reference(
  38. self.cr, self.uid, 'base', 'user_demo')[1]
  39. # Test Section
  40. def test_01_normal_login_admin_succeed(self):
  41. """[Regression Test]
  42. Test the succeed of login with 'admin' / 'admin'"""
  43. res = self.ru_obj.authenticate(self.db, 'admin', 'admin', {})
  44. self.assertEqual(
  45. res, self.admin_user_id,
  46. "'admin' / 'admin' login must succeed.")
  47. def test_02_normal_login_admin_fail(self):
  48. """[Regression Test]
  49. Test the fail of login with 'admin' / 'bad_password'"""
  50. res = self.ru_obj.authenticate(self.db, 'admin', 'bad_password', {})
  51. self.assertEqual(
  52. res, False,
  53. "'admin' / 'bad_password' login must fail.")
  54. def test_03_normal_login_demo_succeed(self):
  55. """[Regression Test]
  56. Test the succeed of login with 'demo' / 'demo'"""
  57. res = self.ru_obj.authenticate(self.db, 'demo', 'demo', {})
  58. self.assertEqual(
  59. res, self.demo_user_id,
  60. "'demo' / 'demo' login must succeed.")
  61. def test_04_normal_login_demo_fail(self):
  62. """[Regression Test]
  63. Test the fail of login with 'demo' / 'bad_password'"""
  64. res = self.ru_obj.authenticate(self.db, 'demo', 'bad_password', {})
  65. self.assertEqual(
  66. res, False,
  67. "'demo' / 'bad_password' login must fail.")
  68. def test_05_passkey_login_demo_succeed(self):
  69. """[New Feature]
  70. Test the succeed of login with 'demo' / 'admin'"""
  71. res = self.ru_obj.authenticate(self.db, 'demo', 'admin', {})
  72. self.assertEqual(
  73. res, self.demo_user_id,
  74. "'demo' / 'admin' login must succeed.")
  75. def test_06_passkey_login_demo_succeed(self):
  76. """[Bug #1319391]
  77. Test the correct behaviour of login with 'bad_login' / 'admin'"""
  78. exception_raised = False
  79. try:
  80. self.ru_obj.authenticate(self.db, 'bad_login', 'admin', {})
  81. except:
  82. exception_raised = True
  83. self.assertEqual(
  84. exception_raised, False,
  85. "'bad_login' / 'admin' musn't raise Error.")