diff options
-rw-r--r-- | sos/cleaner/parsers/hostname_parser.py | 19 | ||||
-rw-r--r-- | tests/unittests/cleaner_tests.py | 7 |
2 files changed, 26 insertions, 0 deletions
diff --git a/sos/cleaner/parsers/hostname_parser.py b/sos/cleaner/parsers/hostname_parser.py index debdf182..07eb40f6 100644 --- a/sos/cleaner/parsers/hostname_parser.py +++ b/sos/cleaner/parsers/hostname_parser.py @@ -8,6 +8,7 @@ # # See the LICENSE file in the source distribution for further information. +import re from sos.cleaner.parsers import SoSCleanerParser from sos.cleaner.mappings.hostname_map import SoSHostnameMap @@ -29,6 +30,24 @@ class SoSHostnameParser(SoSCleanerParser): self.load_short_names_from_mapping() self.mapping.set_initial_counts() + def parse_line(self, line): + """This will be called for every line in every file we process, so that + every parser has a chance to scrub everything. + + We are overriding parent method since we need to swap ordering of + _parse_line_with_compiled_regexes and _parse_line calls. + """ + count = 0 + for skip_pattern in self.skip_line_patterns: + if re.match(skip_pattern, line, re.I): + return line, count + line, _count = self._parse_line(line) + count += _count + if self.compile_regexes: + line, _rcount = self._parse_line_with_compiled_regexes(line) + count += _rcount + return line, count + def load_short_names_from_mapping(self): """When we load the mapping file into the hostname map, we have to do some dancing to get those loaded properly into the "intermediate" dicts diff --git a/tests/unittests/cleaner_tests.py b/tests/unittests/cleaner_tests.py index d27481c1..9759b38a 100644 --- a/tests/unittests/cleaner_tests.py +++ b/tests/unittests/cleaner_tests.py @@ -172,6 +172,13 @@ class CleanerParserTests(unittest.TestCase): _test = self.host_parser.parse_line(line)[0] self.assertNotEqual(line, _test) + def test_obfuscate_whole_fqdn_for_given_domainname(self): + self.host_parser.load_hostname_into_map('sostestdomain.domain') + line = 'let obfuscate soshost.sostestdomain.domain' + _test = self.host_parser.parse_line(line)[0] + self.assertFalse('soshost' in _test) + self.assertFalse('sostestdomain' in _test) + def test_hostname_no_obfuscate_underscore(self): line = 'pam_env.so _why.not_' _test = self.host_parser.parse_line(line)[0] |