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.

71 lines
3.0 KiB

  1. ###################################################################################
  2. #
  3. # Copyright (c) 2017-2019 MuK IT GmbH.
  4. #
  5. # This file is part of MuK Security
  6. # (see https://mukit.at).
  7. #
  8. # This program is free software: you can redistribute it and/or modify
  9. # it under the terms of the GNU Lesser General Public License as published by
  10. # the Free Software Foundation, either version 3 of the License, or
  11. # (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 Lesser General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU Lesser General Public License
  19. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. #
  21. ###################################################################################
  22. import os
  23. import base64
  24. import logging
  25. from odoo import exceptions
  26. from odoo.tests import common
  27. _path = os.path.dirname(os.path.dirname(__file__))
  28. _logger = logging.getLogger(__name__)
  29. class SuspendSecurityTestCase(common.TransactionCase):
  30. def setUp(self):
  31. super(SuspendSecurityTestCase, self).setUp()
  32. def tearDown(self):
  33. super(SuspendSecurityTestCase, self).tearDown()
  34. def test_suspend_security(self):
  35. user_id = self.env.ref('base.user_demo').id
  36. tester = self.env.ref('base.user_root').sudo(user_id)
  37. with self.assertRaises(exceptions.AccessError):
  38. tester.write({'login': 'test'})
  39. tester.suspend_security().write({'login': 'test'})
  40. self.assertEqual(tester.login, 'test')
  41. self.assertEqual(tester.write_uid.id, user_id)
  42. def test_normalize(self):
  43. self.env['res.users'].browse(self.env['res.users'].suspend_security().env.uid)
  44. def test_search_one2many(self):
  45. user = self.env.ref('base.user_demo')
  46. model = self.env['res.partner'].sudo(user.id)
  47. self.assertTrue(model.env.user.id == user.id)
  48. normal_domain = [('user_ids.id', '=', model.env.uid)]
  49. suspend_domain = [('user_ids.id', '=', model.suspend_security().env.uid)]
  50. normal_partner = model.search(normal_domain, limit=1)
  51. suspend_partner = model.search(suspend_domain, limit=1)
  52. self.assertEqual(normal_partner, suspend_partner)
  53. normal_domain = [('user_ids', '=', model.env.uid)]
  54. suspend_domain = [('user_ids', '=', model.suspend_security().env.uid)]
  55. normal_partner = model.search(normal_domain, limit=1)
  56. suspend_partner = model.search(suspend_domain, limit=1)
  57. self.assertEqual(normal_partner, suspend_partner)
  58. normal_domain = [('user_ids.id', 'in', [model.env.uid])]
  59. suspend_domain = [('user_ids.id', 'in', [model.suspend_security().env.uid])]
  60. normal_partner = model.search(normal_domain, limit=1)
  61. suspend_partner = model.search(suspend_domain, limit=1)
  62. self.assertEqual(normal_partner, suspend_partner)