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.

78 lines
2.1 KiB

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