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.

82 lines
2.9 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. import threading
  6. from openerp.tests.common import TransactionCase
  7. class TestAuthAdminPasskey(TransactionCase):
  8. """Tests for 'Auth Admin Passkey' Module"""
  9. # Overload Section
  10. def setUp(self):
  11. super(TestAuthAdminPasskey, self).setUp()
  12. # Get Registries
  13. self.imd_obj = self.registry('ir.model.data')
  14. self.ru_obj = self.registry('res.users')
  15. # Get Database name
  16. self.db = threading.current_thread().dbname
  17. # Get ids from xml_ids
  18. self.admin_user_id = self.imd_obj.get_object_reference(
  19. self.cr, self.uid, 'base', 'user_root')[1]
  20. self.demo_user_id = self.imd_obj.get_object_reference(
  21. self.cr, self.uid, 'base', 'user_demo')[1]
  22. # Test Section
  23. def test_01_normal_login_admin_succeed(self):
  24. """[Regression Test]
  25. Test the succeed of login with 'admin' / 'admin'"""
  26. res = self.ru_obj.authenticate(self.db, 'admin', 'admin', {})
  27. self.assertEqual(
  28. res, self.admin_user_id,
  29. "'admin' / 'admin' login must succeed.")
  30. def test_02_normal_login_admin_fail(self):
  31. """[Regression Test]
  32. Test the fail of login with 'admin' / 'bad_password'"""
  33. res = self.ru_obj.authenticate(self.db, 'admin', 'bad_password', {})
  34. self.assertEqual(
  35. res, False,
  36. "'admin' / 'bad_password' login must fail.")
  37. def test_03_normal_login_demo_succeed(self):
  38. """[Regression Test]
  39. Test the succeed of login with 'demo' / 'demo'"""
  40. res = self.ru_obj.authenticate(self.db, 'demo', 'demo', {})
  41. self.assertEqual(
  42. res, self.demo_user_id,
  43. "'demo' / 'demo' login must succeed.")
  44. def test_04_normal_login_demo_fail(self):
  45. """[Regression Test]
  46. Test the fail of login with 'demo' / 'bad_password'"""
  47. res = self.ru_obj.authenticate(self.db, 'demo', 'bad_password', {})
  48. self.assertEqual(
  49. res, False,
  50. "'demo' / 'bad_password' login must fail.")
  51. def test_05_passkey_login_demo_succeed(self):
  52. """[New Feature]
  53. Test the succeed of login with 'demo' / 'admin'"""
  54. res = self.ru_obj.authenticate(self.db, 'demo', 'admin', {})
  55. self.assertEqual(
  56. res, self.demo_user_id,
  57. "'demo' / 'admin' login must succeed.")
  58. def test_06_passkey_login_demo_succeed(self):
  59. """[Bug #1319391]
  60. Test the correct behaviour of login with 'bad_login' / 'admin'"""
  61. exception_raised = False
  62. try:
  63. self.ru_obj.authenticate(self.db, 'bad_login', 'admin', {})
  64. except:
  65. exception_raised = True
  66. self.assertEqual(
  67. exception_raised, False,
  68. "'bad_login' / 'admin' musn't raise Error.")