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.

66 lines
2.3 KiB

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