diff options
-rw-r--r-- | sos/cleaner/parsers/mac_parser.py | 22 | ||||
-rw-r--r-- | tests/unittests/cleaner_tests.py | 24 |
2 files changed, 38 insertions, 8 deletions
diff --git a/sos/cleaner/parsers/mac_parser.py b/sos/cleaner/parsers/mac_parser.py index 4cbcbdce..d1c61752 100644 --- a/sos/cleaner/parsers/mac_parser.py +++ b/sos/cleaner/parsers/mac_parser.py @@ -14,14 +14,20 @@ from sos.cleaner.mappings.mac_map import SoSMacMap import re # aa:bb:cc:fe:ff:dd:ee:ff -IPV6_REG_8HEX = (r'((?<!([0-9a-fA-F]:)|::)([^:|-])?([0-9a-fA-F]{2}(:|-)){7}' - r'[0-9a-fA-F]{2}(\s|$))') +IPV6_REG_8HEX = ( + r'((?<!([0-9a-fA-F\'\"]:)|::)([^:|-])?([0-9a-fA-F]{2}(:|-)){7}' + r'[0-9a-fA-F]{2}(\'|\")?(\s|$))' +) # aabb:ccee:ddee:ffaa -IPV6_REG_4HEX = (r'((?<!([0-9a-fA-F]:)|::)(([^:\-]?[0-9a-fA-F]{4}(:|-)){3}' - r'[0-9a-fA-F]{4}(\s|$)))') +IPV6_REG_4HEX = ( + r'((?<!([0-9a-fA-F\'\"]:)|::)(([^:\-]?[0-9a-fA-F]{4}(:|-)){3}' + r'[0-9a-fA-F]{4}(\'|\")?(\s|$)))' +) # aa:bb:cc:dd:ee:ff avoiding ipv6 substring matches -IPV4_REG = (r'((?<!([0-9a-fA-F]:)|::)(([^:\-])?([0-9a-fA-F]{2}([:-])){5}' - r'([0-9a-fA-F]){2}(\s|$)))') +IPV4_REG = ( + r'((?<!([0-9a-fA-F\'\"]:)|::)(([^:\-])?([0-9a-fA-F]{2}([:-])){5}' + r'([0-9a-fA-F]){2}(\'|\")?(\s|$)))' +) class SoSMacParser(SoSCleanerParser): @@ -65,10 +71,10 @@ class SoSMacParser(SoSCleanerParser): if matches: count += len(matches) for match in matches: - if match.startswith(self.obfuscated_patterns): + stripped_match = self.reduce_mac_match(match) + if stripped_match.startswith(self.obfuscated_patterns): # avoid double scrubbing continue - stripped_match = self.reduce_mac_match(match) new_match = self.mapping.get(stripped_match) line = line.replace(stripped_match, new_match) return line, count diff --git a/tests/unittests/cleaner_tests.py b/tests/unittests/cleaner_tests.py index b59eade9..39f81a78 100644 --- a/tests/unittests/cleaner_tests.py +++ b/tests/unittests/cleaner_tests.py @@ -131,6 +131,30 @@ class CleanerParserTests(unittest.TestCase): _test = self.mac_parser.parse_line(line)[0] self.assertNotEqual(line, _test) + def test_mac_parser_with_quotes(self): + line = "foobar foo '12:34:56:78:90:AA' bar barfoo" + _test = self.mac_parser.parse_line(line)[0] + self.assertNotEqual(line, _test) + dline = 'foobar foo "aa:12:bb:34:cc:56" bar barfoo' + _dtest = self.mac_parser.parse_line(dline)[0] + self.assertNotEqual(dline, _dtest) + + def test_mac_parser_with_quotes_ipv6(self): + line = "foobar foo 'FF:EE:DD:FF:FE:CC:BB:AA' bar barfoo" + _test = self.mac_parser.parse_line(line)[0] + self.assertNotEqual(line, _test) + dline = 'foobar foo "DD:EE:FF:FF:FE:BB:CC:AA" bar barfoo' + _dtest = self.mac_parser.parse_line(dline)[0] + self.assertNotEqual(dline, _dtest) + + def test_mac_parser_with_quotes_ipv6_quad(self): + line = "foobar foo 'AABB:CCDD:EEFF:FFAA' bar barfoo" + _test = self.mac_parser.parse_line(line)[0] + self.assertNotEqual(line, _test) + dline = 'foobar foo "AAFF:FFEE:DDCC:BBAA" bar barfoo' + _dtest = self.mac_parser.parse_line(dline)[0] + self.assertNotEqual(dline, _dtest) + def test_hostname_load_hostname_string(self): fqdn = 'myhost.subnet.example.com' self.host_parser.load_hostname_into_map(fqdn) |