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.

63 lines
2.2 KiB

  1. # Copyright 2018 Creu Blanca
  2. # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
  3. from mock import patch
  4. from werkzeug.utils import redirect
  5. from odoo import http
  6. from odoo.tests.common import at_install, HttpCase, post_install
  7. @at_install(False)
  8. @post_install(True)
  9. # Skip CSRF validation on tests
  10. @patch(http.__name__ + ".WebRequest.validate_csrf", return_value=True)
  11. # Skip specific browser forgery on redirections
  12. @patch(http.__name__ + ".redirect_with_hash", side_effect=redirect)
  13. class TestRemote(HttpCase):
  14. def setUp(self):
  15. super().setUp()
  16. # HACK https://github.com/odoo/odoo/issues/24183
  17. # TODO Remove in v12
  18. # Complex password to avoid conflicts with `password_security`
  19. self.good_password = "Admin$%02584"
  20. self.data_demo = {
  21. "login": "demo",
  22. "password": "Demo%&/(908409**",
  23. }
  24. self.remote_addr = '127.0.0.1'
  25. with self.cursor() as cr:
  26. env = self.env(cr)
  27. # Make sure involved users have good passwords
  28. env.user.password = self.good_password
  29. env["res.users"].search([
  30. ("login", "=", self.data_demo["login"]),
  31. ]).password = self.data_demo["password"]
  32. remote = self.env['res.remote'].search([
  33. ('ip', '=', self.remote_addr)
  34. ])
  35. if remote:
  36. remote.unlink()
  37. def test_xmlrpc_login_ok(self, *args):
  38. """Test Login"""
  39. data1 = self.data_demo
  40. self.assertTrue(self.xmlrpc_common.authenticate(
  41. self.env.cr.dbname, data1["login"], data1["password"], {}))
  42. with self.cursor() as cr:
  43. env = self.env(cr)
  44. self.assertTrue(
  45. env['res.remote'].search([('ip', '=', self.remote_addr)])
  46. )
  47. def test_xmlrpc_login_failure(self, *args):
  48. """Test Login Failure"""
  49. data1 = self.data_demo
  50. data1['password'] = 'Failure!'
  51. self.assertFalse(self.xmlrpc_common.authenticate(
  52. self.env.cr.dbname, data1["login"], data1["password"], {}))
  53. with self.cursor() as cr:
  54. env = self.env(cr)
  55. self.assertTrue(
  56. env['res.remote'].search([('ip', '=', self.remote_addr)])
  57. )