diff options
author | Jake Hunsaker <jhunsake@redhat.com> | 2022-12-02 16:20:01 -0500 |
---|---|---|
committer | Jake Hunsaker <jhunsake@redhat.com> | 2023-01-12 12:21:25 -0500 |
commit | 131b3bcf5691a158598bed30bd0af6ac9c96737c (patch) | |
tree | e70b824a077300eea34513a6305568c38696ac79 /tests/cleaner_tests/full_report | |
parent | ca8a8a7b9f452a81c5654234918b99092620bf13 (diff) | |
download | sos-131b3bcf5691a158598bed30bd0af6ac9c96737c.tar.gz |
[testing] Change location of mocked files for tests
Previously, mocked files were kept under the `tests/test_data/`
directory and generally mimic'd the file location they would be
temporarily copied to during the execution of their relevant tests.
This has a few maintainability drawbacks, and the handling of the
`files` attribute for test cases as either strings or tuples is at best
confusing.
Improve on this by instead making the `files` references relative to
where the test case file is written. This enables easier maintenance by
keeping all test requirements closer together, rather than spread across
the repo. As such, the `files` attribute now requires a list of tuples,
taking the form `(relative_src, absolute_dest)`. Additionally, fake
plugins for tests that need them to artificially test a specific
criteria should also be included in the test's subdir now.
Along with this change, move several StageTwo tests to their own subdirs
that now contain both the test cases and the needed files for mocking.
This should be the new design pattern going forward - if a test needs to
mock files of any kind, put it in a new subdirectory (and if it doesn't
need to mock files, continue to keep it in the relevant directory within
the test suite).
Signed-off-by: Jake Hunsaker <jhunsake@redhat.com>
Diffstat (limited to 'tests/cleaner_tests/full_report')
-rw-r--r-- | tests/cleaner_tests/full_report/default_mapping | 0 | ||||
-rw-r--r-- | tests/cleaner_tests/full_report/full_report_run.py | 86 |
2 files changed, 86 insertions, 0 deletions
diff --git a/tests/cleaner_tests/full_report/default_mapping b/tests/cleaner_tests/full_report/default_mapping new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/tests/cleaner_tests/full_report/default_mapping diff --git a/tests/cleaner_tests/full_report/full_report_run.py b/tests/cleaner_tests/full_report/full_report_run.py new file mode 100644 index 00000000..d17287a8 --- /dev/null +++ b/tests/cleaner_tests/full_report/full_report_run.py @@ -0,0 +1,86 @@ +# 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. + +import json +import re + +from avocado.utils import process +from sos_tests import StageTwoReportTest + + +class FullCleanTest(StageTwoReportTest): + """Run an unrestricted report execution through sos clean, ensuring that + our obfuscation is reliable across arbitrary plugin sets and not just the + 'main' plugins that tend to collect data needing obfuscation + + :avocado: tags=stagetwo + """ + + sos_cmd = '-v --clean' + sos_timeout = 600 + # replace with an empty placeholder, make sure that this test case is not + # influenced by previous clean runs + files = [('default_mapping', '/etc/sos/cleaner/default_mapping')] + packages = { + 'rhel': ['python3-systemd'], + 'ubuntu': ['python3-systemd'] + } + + def pre_sos_setup(self): + # ensure that case-insensitive matching of FQDNs and shortnames work + from systemd import journal + from socket import gethostname + host = gethostname() + short = host.split('.')[0] + sosfd = journal.stream('sos-testing') + sosfd.write( + "This is a test line from sos clean testing. The hostname %s " + "should not appear, nor should %s in an obfuscated archive. The " + "shortnames of %s and %s should also not appear." + % (host.lower(), host.upper(), short.lower(), short.upper()) + ) + + 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_archive_type_correct(self): + self.assertSosLogContains('Loaded .* as type sos report directory') + + def test_hostname_not_in_any_file(self): + host = self.sysinfo['pre']['networking']['hostname'] + short = host.split('.')[0] + # much faster to just use grep here + content = self.grep_for_content(host) + self.grep_for_content(short) + if not content: + assert True + else: + self.fail("Hostname appears in files: %s" + % "\n".join(f for f in content)) + + def test_no_empty_obfuscations(self): + # get the private map file name + map_file = re.findall('/.*sosreport-.*-private_map', self.cmd_output.stdout)[-1] + with open(map_file, 'r') as mf: + map_json = json.load(mf) + for mapping in map_json: + for key, val in map_json[mapping].items(): + assert key, "Empty key found in %s" % mapping + assert val, "%s mapping for '%s' empty" % (mapping, key) + + def test_ip_not_in_any_file(self): + ip = self.sysinfo['pre']['networking']['ip_addr'] + content = self.grep_for_content(ip) + if not content: + assert True + else: + self.fail("IP appears in files: %s" % "\n".join(f for f in content)) |