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.

62 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. # Complex password to avoid conflicts with `password_security`
  17. self.good_password = "Admin$%02584"
  18. self.data_demo = {
  19. "login": "demo",
  20. "password": "Demo%&/(908409**",
  21. }
  22. self.remote_addr = '127.0.0.1'
  23. with self.cursor() as cr:
  24. env = self.env(cr)
  25. # Make sure involved users have good passwords
  26. env.user.password = self.good_password
  27. env["res.users"].search([
  28. ("login", "=", self.data_demo["login"]),
  29. ]).password = self.data_demo["password"]
  30. remote = self.env['res.remote'].search([
  31. ('ip', '=', self.remote_addr)
  32. ])
  33. if remote:
  34. remote.unlink()
  35. def test_xmlrpc_login_ok(self, *args):
  36. """Test Login"""
  37. data1 = self.data_demo
  38. self.assertTrue(self.xmlrpc_common.authenticate(
  39. self.env.cr.dbname, data1["login"], data1["password"], {}))
  40. with self.cursor() as cr:
  41. env = self.env(cr)
  42. self.assertTrue(
  43. env['res.remote'].search([('ip', '=', self.remote_addr)])
  44. )
  45. def test_xmlrpc_login_failure(self, *args):
  46. """Test Login Failure"""
  47. data1 = self.data_demo
  48. data1['password'] = 'Failure!'
  49. self.assertFalse(self.xmlrpc_common.authenticate(
  50. self.env.cr.dbname, data1["login"], data1["password"], {}))
  51. with self.cursor() as cr:
  52. env = self.env(cr)
  53. self.assertTrue(
  54. env['res.remote'].search([('ip', '=', self.remote_addr)])
  55. )