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.

77 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. import unittest
  4. import mock
  5. from ..logutils import SanitizeOdooCookiesProcessor
  6. class TestOdooCookieSanitizer(unittest.TestCase):
  7. def test_cookie_as_string(self):
  8. data = {
  9. 'request': {
  10. 'cookies': 'website_lang=en_us;'
  11. 'session_id=hello;'
  12. 'Session_ID=hello;'
  13. 'foo=bar',
  14. },
  15. }
  16. proc = SanitizeOdooCookiesProcessor(mock.Mock())
  17. result = proc.process(data)
  18. self.assertTrue('request' in result)
  19. http = result['request']
  20. self.assertEqual(
  21. http['cookies'],
  22. 'website_lang=en_us;'
  23. 'session_id={m};'
  24. 'Session_ID={m};'
  25. 'foo=bar'.format(
  26. m=proc.MASK,
  27. ),
  28. )
  29. def test_cookie_as_string_with_partials(self):
  30. data = {
  31. 'request': {
  32. 'cookies': 'website_lang=en_us;session_id;foo=bar',
  33. },
  34. }
  35. proc = SanitizeOdooCookiesProcessor(mock.Mock())
  36. result = proc.process(data)
  37. self.assertTrue('request' in result)
  38. http = result['request']
  39. self.assertEqual(
  40. http['cookies'],
  41. 'website_lang=en_us;session_id;foo=bar'.format(m=proc.MASK),
  42. )
  43. def test_cookie_header(self):
  44. data = {
  45. 'request': {
  46. 'headers': {
  47. 'Cookie': 'foo=bar;'
  48. 'session_id=hello;'
  49. 'Session_ID=hello;'
  50. 'a_session_id_here=hello',
  51. },
  52. },
  53. }
  54. proc = SanitizeOdooCookiesProcessor(mock.Mock())
  55. result = proc.process(data)
  56. self.assertTrue('request' in result)
  57. http = result['request']
  58. self.assertEqual(
  59. http['headers']['Cookie'],
  60. 'foo=bar;'
  61. 'session_id={m};'
  62. 'Session_ID={m};'
  63. 'a_session_id_here={m}'.format(m=proc.MASK))