aboutsummaryrefslogtreecommitdiffstats
path: root/tests/cleaner_tests.py
diff options
context:
space:
mode:
authorJake Hunsaker <jhunsake@redhat.com>2020-05-28 10:39:35 -0400
committerJake Hunsaker <jhunsake@redhat.com>2020-06-17 12:11:29 -0400
commit33bfe244f66af4dedee887799db0b6eaf85c9f08 (patch)
tree6120ee9a5c0866a7229bdb3542d1f09dfc94eb7f /tests/cleaner_tests.py
parentaf0f418b7f5fd677cf153b97c7a8f980b5728aaf (diff)
downloadsos-33bfe244f66af4dedee887799db0b6eaf85c9f08.tar.gz
[cleaner] Add hostname parser
Adds a hostname parser to `sos clean` that will attempt to obfuscate FQDNs matching the hostname of the system that generated the sosreport, as found in sos_commands/host/hostname. Additionally, any domains added via the `--domains` option will also be obfuscated, including any subdomains of the domain(s) specified by the option. Signed-off-by: Jake Hunsaker <jhunsake@redhat.com>
Diffstat (limited to 'tests/cleaner_tests.py')
-rw-r--r--tests/cleaner_tests.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/cleaner_tests.py b/tests/cleaner_tests.py
index 0c6ac589..4e292a05 100644
--- a/tests/cleaner_tests.py
+++ b/tests/cleaner_tests.py
@@ -11,8 +11,10 @@ import unittest
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.mappings.ip_map import SoSIPMap
from sos.cleaner.mappings.mac_map import SoSMacMap
+from sos.cleaner.mappings.hostname_map import SoSHostnameMap
class CleanerMapTests(unittest.TestCase):
@@ -20,6 +22,7 @@ class CleanerMapTests(unittest.TestCase):
def setUp(self):
self.mac_map = SoSMacMap()
self.ip_map = SoSIPMap()
+ self.host_map = SoSHostnameMap(['redhat.com'])
def test_mac_map_obfuscate_valid_v4(self):
_test = self.mac_map.get('12:34:56:78:90:ab')
@@ -65,12 +68,33 @@ class CleanerMapTests(unittest.TestCase):
_test = self.ip_map.get('127.0.0.1')
self.assertEquals(_test, '127.0.0.1')
+ def test_hostname_obfuscate_domain_options(self):
+ _test = self.host_map.get('www.redhat.com')
+ self.assertNotEqual(_test, 'www.redhat.com')
+
+ def test_hostname_obfuscate_same_item(self):
+ _test1 = self.host_map.get('example.redhat.com')
+ _test2 = self.host_map.get('example.redhat.com')
+ self.assertEqual(_test1, _test2)
+
+ def test_hostname_obfuscate_just_domain(self):
+ _test = self.host_map.get('redhat.com')
+ self.assertEqual(_test, 'obfuscateddomain0.com')
+
+ def test_hostname_no_obfuscate_non_loaded_domain(self):
+ _test = self.host_map.get('foobar.com')
+ self.assertEqual(_test, 'foobar.com')
+
+ def test_hostname_no_obfuscate_non_loaded_fqdn(self):
+ _test = self.host_map.get('example.foobar.com')
+ self.assertEqual(_test, 'example.foobar.com')
class CleanerParserTests(unittest.TestCase):
def setUp(self):
self.ip_parser = SoSIPParser()
self.mac_parser = SoSMacParser()
+ self.host_parser = SoSHostnameParser(opt_domains='foobar.com')
def test_ip_parser_valid_ipv4_line(self):
line = 'foobar foo 10.0.0.1/24 barfoo bar'
@@ -95,3 +119,19 @@ class CleanerParserTests(unittest.TestCase):
line = 'foobar foo AA:BB:CC:FF:FE:DD:EE:FF bar barfoo'
_test = self.mac_parser.parse_line(line)[0]
self.assertNotEqual(line, _test)
+
+ def test_hostname_load_hostname_string(self):
+ fqdn = 'myhost.subnet.example.com'
+ self.host_parser.load_hostname_into_map(fqdn)
+
+ def test_hostname_valid_domain_line(self):
+ self.host_parser.load_hostname_into_map('myhost.subnet.example.com')
+ line = 'testing myhost.subnet.example.com in a string'
+ _test = self.host_parser.parse_line(line)[0]
+ self.assertNotEqual(line, _test)
+
+ def test_hostname_short_name_in_line(self):
+ self.host_parser.load_hostname_into_map('myhost.subnet.example.com')
+ line = 'testing just myhost in a line'
+ _test = self.host_parser.parse_line(line)[0]
+ self.assertNotEqual(line, _test)