diff options
Diffstat (limited to 'tests/report_tests')
-rw-r--r-- | tests/report_tests/__init__.py | 1 | ||||
-rw-r--r-- | tests/report_tests/basic_report_tests.py | 80 | ||||
-rw-r--r-- | tests/report_tests/plugin_tests/__init__.py | 0 | ||||
-rw-r--r-- | tests/report_tests/plugin_tests/networking.py | 31 | ||||
-rw-r--r-- | tests/report_tests/report_with_mask.py | 69 |
5 files changed, 181 insertions, 0 deletions
diff --git a/tests/report_tests/__init__.py b/tests/report_tests/__init__.py new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/tests/report_tests/__init__.py @@ -0,0 +1 @@ + diff --git a/tests/report_tests/basic_report_tests.py b/tests/report_tests/basic_report_tests.py new file mode 100644 index 00000000..0cf5bd4e --- /dev/null +++ b/tests/report_tests/basic_report_tests.py @@ -0,0 +1,80 @@ +# This file is part of the sos project: https://github.com/sosreport/sos +# +# This copyrighted material is made available to anyone wishing to use, +# modify, copy, or redistribute it subject to the terms and conditions of +# version 2 of the GNU General Public License. +# +# See the LICENSE file in the source distribution for further information. + + +from sos_tests import StageOneReportTest + + +class NormalSoSReport(StageOneReportTest): + """ + :avocado: tags=stageone + """ + + sos_cmd = '-vvv --label thisismylabel' + + def test_debug_in_logs_verbose(self): + self.assertSosLogContains('DEBUG') + + def test_postproc_called(self): + self.assertSosLogContains('substituting scrpath') + + def test_label_applied_to_archive(self): + self.assertTrue('thisismylabel' in self.archive) + + def test_free_symlink_created(self): + self.assertFileCollected('free') + + +class RestrictedSoSReport(StageOneReportTest): + """ + :avocado: tags=stageone + """ + + sos_cmd = '-o kernel,host,sudo,hardware,dbus,x11 --no-env-var --no-report -t1 --no-postproc' + + def test_no_env_vars_collected(self): + self.assertFileNotCollected('environment') + + def test_no_reports_generated(self): + self.assertFileNotCollected('sos_reports/sos.html') + self.assertFileNotCollected('sos_reports/sos.json') + self.assertFileNotCollected('sos_reports/sos.txt') + + def test_was_single_threaded_run(self): + self.assertOutputNotContains('Finishing plugins') + + def test_postproc_not_called(self): + self.assertOutputNotContains('substituting') + + def test_only_selected_plugins_run(self): + self.assertOnlyPluginsIncluded(['kernel', 'host', 'sudo', 'hardware', 'dbus', 'x11']) + + +class DisabledCollectionsReport(StageOneReportTest): + """ + :avocado: tags=stageone + """ + + sos_cmd = "-n networking,system,logs --skip-files=/etc/fstab --skip-commands='journalctl*'" + + def test_plugins_disabled(self): + self.assertPluginNotIncluded('networking') + self.assertPluginNotIncluded('system') + self.assertPluginNotIncluded('logs') + + def test_skipped_plugins_have_no_dir(self): + self.assertFileNotCollected('sos_commands/networking/') + self.assertFileNotCollected('sos_commands/system/') + self.assertFileNotCollected('sos_commands/logs/') + + def test_skip_files_working(self): + self.assertFileNotCollected('/etc/fstab') + + def test_skip_commands_working(self): + self.assertFileGlobNotInArchive('sos_commands/*/journalctl*') + diff --git a/tests/report_tests/plugin_tests/__init__.py b/tests/report_tests/plugin_tests/__init__.py new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/tests/report_tests/plugin_tests/__init__.py diff --git a/tests/report_tests/plugin_tests/networking.py b/tests/report_tests/plugin_tests/networking.py new file mode 100644 index 00000000..f6cfa2d8 --- /dev/null +++ b/tests/report_tests/plugin_tests/networking.py @@ -0,0 +1,31 @@ +# This file is part of the sos project: https://github.com/sosreport/sos +# +# This copyrighted material is made available to anyone wishing to use, +# modify, copy, or redistribute it subject to the terms and conditions of +# version 2 of the GNU General Public License. +# +# See the LICENSE file in the source distribution for further information. + + +from sos_tests import StageOneReportTest + + +class NetworkingPluginTest(StageOneReportTest): + """ + Basic tests to ensure proper collection from the networking plugins + + :avocado: tags=stageone + """ + + sos_cmd = '-o networking' + + def test_common_files_collected(self): + self.assertFileCollected('/etc/resolv.conf') + self.assertFileCollected('/etc/hosts') + + def test_ip_addr_symlink_created(self): + self.assertFileCollected('ip_addr') + + def test_forbidden_globs_skipped(self): + self.assertFileGlobNotInArchive('/proc/net/rpc/*/channel') + self.assertFileGlobNotInArchive('/proc/net/rpc/*/flush') diff --git a/tests/report_tests/report_with_mask.py b/tests/report_tests/report_with_mask.py new file mode 100644 index 00000000..a62888ae --- /dev/null +++ b/tests/report_tests/report_with_mask.py @@ -0,0 +1,69 @@ +# This file is part of the sos project: https://github.com/sosreport/sos +# +# This copyrighted material is made available to anyone wishing to use, +# modify, copy, or redistribute it subject to the terms and conditions of +# version 2 of the GNU General Public License. +# +# See the LICENSE file in the source distribution for further information. + +from sos_tests import StageOneReportTest + +import re + + +class ReportWithMask(StageOneReportTest): + """Testing around basic --clean/--mask usage and expectations + + :avocado: tags=stageone + """ + + sos_cmd = '--mask -o host,networking' + + def test_mask_was_run(self): + self.assertOutputContains('Beginning obfuscation') + self.assertOutputContains('Obfuscation completed') + + def test_private_map_was_generated(self): + self.assertOutputContains('A mapping of obfuscated elements is available at') + map_file = re.findall('/.*sosreport-.*-private_map', self.cmd_output.stdout)[-1] + self.assertFileExists(map_file) + + def test_tarball_named_obfuscated(self): + self.assertTrue('obfuscated' in self.archive) + + def test_localhost_was_obfuscated(self): + self.assertFileHasContent('/etc/hostname', 'host0') + + def test_ip_address_was_obfuscated(self): + # Note: do not test for starting with the 100.* block here, as test + # machines may have /32 addresses. Instead, test that the actual + # IP address is not present + self.assertFileNotHasContent('ip_addr', self.sysinfo['pre']['networking']['ip_addr']) + + def test_loopback_was_not_obfuscated(self): + self.assertFileHasContent('ip_addr', '127.0.0.1/8') + + def test_mac_addrs_were_obfuscated(self): + content = self.get_file_content('sos_commands/networking/ip_maddr_show') + for line in content.splitlines(): + if line.strip().startswith('link'): + mac = line.strip().split()[1] + assert mac.startswith('53:4f:53'), "Found unobfuscated mac addr %s" % mac + + +class ReportWithCleanedKeywords(StageOneReportTest): + """Testing for obfuscated keywords provided by the user + + :avocado: tags=stageone + """ + + sos_cmd = '--clean -o filesys,kernel --keywords=fstab,Linux' + + # Ok, sort of cheesy here but this does actually test filename changes on + # a file common to all distros + def test_filename_obfuscated(self): + self.assertFileNotCollected('/etc/fstab') + self.assertFileGlobInArchive('/etc/obfuscatedword*') + + def test_keyword_obfuscated_in_file(self): + self.assertFileNotHasContent('sos_commands/kernel/uname_-a', 'Linux') |