test_dehashing.py 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. # Copyright 2025 Google LLC
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. #/usr/bin/env python
  15. """
  16. Tests for pebble.loghashing.dehashing
  17. """
  18. LOOKUP_DICT = {"13108": "activity.c:activity tracking started",
  19. "45803": "ispp.c:Start Authentication Process (%d) %s"}
  20. from pebble.loghashing.dehashing import (dehash_line, parse_line, parse_support_line, parse_message,
  21. dehash_str, parse_args)
  22. def test_dehash_file():
  23. """
  24. Test for dehash_file()
  25. """
  26. pass
  27. def test_dehash_line():
  28. """
  29. Test for dehash_line()
  30. """
  31. # Console Line - No arguments
  32. assert ("D A 21:35:14.375 activity.c:804> activity tracking started" ==
  33. dehash_line("D A 21:35:14.375 :804> LH:3334", LOOKUP_DICT))
  34. # Console Line - Arguments
  35. assert ("D A 21:35:14.375 ispp.c:872> Start Authentication Process (2) Success" ==
  36. dehash_line("D A 21:35:14.375 :872> LH:b2eb 2 `Success`", LOOKUP_DICT))
  37. # Support Line - No arguments
  38. assert ("2015-09-05 02:16:16:000GMT activity.c:804> activity tracking started" ==
  39. dehash_line("2015-09-05 02:16:16:000GMT :804 LH:3334", LOOKUP_DICT))
  40. # Support Line - Arguments
  41. assert ("2015-09-05 02:16:19:000GMT ispp.c:872> Start Authentication Process (2) Success" ==
  42. dehash_line("2015-09-05 02:16:19:000GMT :872 LH:b2eb 2 `Success`", LOOKUP_DICT))
  43. def test_parse_line():
  44. """
  45. Test for parse_line()
  46. """
  47. # No arguments
  48. assert ("D A 21:35:14.375 activity.c:804> activity tracking started" ==
  49. parse_line("D A 21:35:14.375 :804> LH:3334", LOOKUP_DICT))
  50. # Arguments
  51. assert ("D A 21:35:14.375 ispp.c:872> Start Authentication Process (2) Success" ==
  52. parse_line("D A 21:35:14.375 :872> LH:b2eb 2 `Success`", LOOKUP_DICT))
  53. def test_parse_support_line():
  54. """
  55. Test for parse_support_line()
  56. """
  57. # No arguments
  58. assert ("2015-09-05 02:16:16:000GMT activity.c:804> activity tracking started" ==
  59. parse_support_line("2015-09-05 02:16:16:000GMT :804 LH:3334", LOOKUP_DICT))
  60. # Arguments
  61. assert ("2015-09-05 02:16:19:000GMT ispp.c:872> Start Authentication Process (2) Success" ==
  62. parse_support_line("2015-09-05 02:16:19:000GMT :872 LH:b2eb 2 `Success`", LOOKUP_DICT))
  63. def test_parse_message():
  64. """
  65. Test for parse_message()
  66. """
  67. # Console Line - No arguments
  68. assert ({'msg': 'activity tracking started', 'line': '804', 'file': 'activity.c'} ==
  69. parse_message(":804> LH:3334", LOOKUP_DICT))
  70. # Console Line - Arguments
  71. assert ({'msg': 'Start Authentication Process (2) Success', 'line': '872', 'file': 'ispp.c'} ==
  72. parse_message(":872> LH:b2eb 2 `Success`", LOOKUP_DICT))
  73. # Support Line - No arguments
  74. assert ({'msg': 'activity tracking started', 'line': '804', 'file': 'activity.c'} ==
  75. parse_message(":804 LH:3334", LOOKUP_DICT))
  76. # Support Line - Arguments
  77. assert ({'msg': 'Start Authentication Process (2) Success', 'line': '872', 'file': 'ispp.c'} ==
  78. parse_message(":872 LH:b2eb 2 `Success`", LOOKUP_DICT))
  79. def test_dehash_str():
  80. """
  81. Test for dehash_str()
  82. """
  83. # No arguments
  84. assert ("activity.c:activity tracking started" ==
  85. dehash_str("3334", LOOKUP_DICT))
  86. # Arguments
  87. assert ("ispp.c:Start Authentication Process (%d) %s" ==
  88. dehash_str("b2eb", LOOKUP_DICT))
  89. def test_parse_args():
  90. """
  91. Test for parse_args()
  92. """
  93. # No `` delimted strings
  94. assert ["foo", "bar", "baz"] == parse_args("foo bar baz")
  95. # `` delimited strings
  96. assert ["foo", "bar baz"] == parse_args("foo `bar baz`")