diff options
author | Jake Hunsaker <jhunsake@redhat.com> | 2020-06-09 12:40:17 -0400 |
---|---|---|
committer | Jake Hunsaker <jhunsake@redhat.com> | 2020-06-17 12:11:29 -0400 |
commit | 2d73f01ec7d96eb242517e008793c7f3a20e753f (patch) | |
tree | 060188bdf85ff39d39b7be1b48b65927e5cf8c29 /tests | |
parent | e7b91722b20a51555cf86dbaa36ba840fe6d6350 (diff) | |
download | sos-2d73f01ec7d96eb242517e008793c7f3a20e753f.tar.gz |
[cleaner] Add user-provided keyword obfuscation
Adds a new parser and map to allow user defined keyword obfuscation.
Users may now use the `--keywords` option to have `SoSCleaner` scan
lines for matching keywords, and replace them in place like we do for
other parsers.
Signed-off-by: Jake Hunsaker <jhunsake@redhat.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/cleaner_tests.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/tests/cleaner_tests.py b/tests/cleaner_tests.py index 4e292a05..aee1147d 100644 --- a/tests/cleaner_tests.py +++ b/tests/cleaner_tests.py @@ -12,9 +12,11 @@ from ipaddress import ip_interface from sos.cleaner.parsers.ip_parser import SoSIPParser from sos.cleaner.parsers.mac_parser import SoSMacParser from sos.cleaner.parsers.hostname_parser import SoSHostnameParser +from sos.cleaner.parsers.keyword_parser import SoSKeywordParser from sos.cleaner.mappings.ip_map import SoSIPMap from sos.cleaner.mappings.mac_map import SoSMacMap from sos.cleaner.mappings.hostname_map import SoSHostnameMap +from sos.cleaner.mappings.keyword_map import SoSKeywordMap class CleanerMapTests(unittest.TestCase): @@ -23,6 +25,7 @@ class CleanerMapTests(unittest.TestCase): self.mac_map = SoSMacMap() self.ip_map = SoSIPMap() self.host_map = SoSHostnameMap(['redhat.com']) + self.kw_map = SoSKeywordMap() def test_mac_map_obfuscate_valid_v4(self): _test = self.mac_map.get('12:34:56:78:90:ab') @@ -89,12 +92,19 @@ class CleanerMapTests(unittest.TestCase): _test = self.host_map.get('example.foobar.com') self.assertEqual(_test, 'example.foobar.com') + def test_keyword_single(self): + _test = self.kw_map.get('foobar') + self.assertEqual(_test, 'obfuscatedword0') + + class CleanerParserTests(unittest.TestCase): def setUp(self): self.ip_parser = SoSIPParser() self.mac_parser = SoSMacParser() self.host_parser = SoSHostnameParser(opt_domains='foobar.com') + self.kw_parser = SoSKeywordParser(keywords=['foobar']) + self.kw_parser_none = SoSKeywordParser() def test_ip_parser_valid_ipv4_line(self): line = 'foobar foo 10.0.0.1/24 barfoo bar' @@ -135,3 +145,13 @@ class CleanerParserTests(unittest.TestCase): line = 'testing just myhost in a line' _test = self.host_parser.parse_line(line)[0] self.assertNotEqual(line, _test) + + def test_keyword_parser_valid_line(self): + line = 'this is my foobar test line' + _test = self.kw_parser.parse_line(line)[0] + self.assertNotEqual(line, _test) + + def test_keyword_parser_no_change_by_default(self): + line = 'this is my foobar test line' + _test = self.kw_parser_none.parse_line(line)[0] + self.assertEqual(line, _test) |