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.

75 lines
2.1 KiB

  1. # Copyright 2016-2017 Versada <https://versada.eu/>
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  3. from odoo.tests import TransactionCase
  4. from ..logutils import SanitizeOdooCookiesProcessor
  5. class TestOdooCookieSanitizer(TransactionCase):
  6. def test_cookie_as_string(self):
  7. data = {
  8. 'request': {
  9. 'cookies': 'website_lang=en_us;'
  10. 'session_id=hello;'
  11. 'Session_ID=hello;'
  12. 'foo=bar',
  13. },
  14. }
  15. proc = SanitizeOdooCookiesProcessor()
  16. result = proc.process(data)
  17. self.assertTrue('request' in result)
  18. http = result['request']
  19. self.assertEqual(
  20. http['cookies'],
  21. 'website_lang=en_us;'
  22. 'session_id={m};'
  23. 'Session_ID={m};'
  24. 'foo=bar'.format(
  25. m=proc.MASK,
  26. ),
  27. )
  28. def test_cookie_as_string_with_partials(self):
  29. data = {
  30. 'request': {
  31. 'cookies': 'website_lang=en_us;session_id;foo=bar',
  32. },
  33. }
  34. proc = SanitizeOdooCookiesProcessor()
  35. result = proc.process(data)
  36. self.assertTrue('request' in result)
  37. http = result['request']
  38. self.assertEqual(
  39. http['cookies'],
  40. 'website_lang=en_us;session_id;foo=bar',
  41. )
  42. def test_cookie_header(self):
  43. data = {
  44. 'request': {
  45. 'headers': {
  46. 'Cookie': 'foo=bar;'
  47. 'session_id=hello;'
  48. 'Session_ID=hello;'
  49. 'a_session_id_here=hello',
  50. },
  51. },
  52. }
  53. proc = SanitizeOdooCookiesProcessor()
  54. result = proc.process(data)
  55. self.assertTrue('request' in result)
  56. http = result['request']
  57. self.assertEqual(
  58. http['headers']['Cookie'],
  59. 'foo=bar;'
  60. 'session_id={m};'
  61. 'Session_ID={m};'
  62. 'a_session_id_here={m}'.format(m=proc.MASK))