From 7240a8fc32dbfcf17d6d9b165b00311ad9591214 Mon Sep 17 00:00:00 2001 From: Jake Hunsaker Date: Tue, 28 Jun 2022 17:46:49 -0400 Subject: [clean,IP Parser] Skip obvious version files for the IP parser For files that can be considered obvious version files - those that end specifically with either `version` or `version.txt` - skip processing via the IP parser, as this may lead to improper obfuscation of certain version strings. This is also applied to files ending in `release`. Closes: #2962 Signed-off-by: Jake Hunsaker --- tests/cleaner_tests/skip_version_ip_parser.py | 33 +++++++++++++++++++++++++++ tests/test_data/fake_plugins/skip_versions.py | 24 +++++++++++++++++++ tests/test_data/tmp/sos-test-version-noskip | 6 +++++ tests/test_data/tmp/sos-test-version.txt | 6 +++++ 4 files changed, 69 insertions(+) create mode 100644 tests/cleaner_tests/skip_version_ip_parser.py create mode 100644 tests/test_data/fake_plugins/skip_versions.py create mode 100644 tests/test_data/tmp/sos-test-version-noskip create mode 100644 tests/test_data/tmp/sos-test-version.txt (limited to 'tests') diff --git a/tests/cleaner_tests/skip_version_ip_parser.py b/tests/cleaner_tests/skip_version_ip_parser.py new file mode 100644 index 00000000..882244ea --- /dev/null +++ b/tests/cleaner_tests/skip_version_ip_parser.py @@ -0,0 +1,33 @@ +# 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 StageTwoReportTest + +DO_SKIP = '/tmp/sos-test-version.txt' +NO_SKIP = '/tmp/sos-test-version-noskip' + +class SkipVersionIPParser(StageTwoReportTest): + """Ensures that we _skip_ files ending in 'version' (or 'version.txt') to + avoid incorrectly obfuscating version numbers. + + :avocado: tags=stagetwo + """ + + files = [DO_SKIP, NO_SKIP] + install_plugins = ['skip_versions'] + sos_cmd = '--clean -o skip_versions' + + def test_version_file_skipped(self): + self.assertFileCollected(DO_SKIP) + self.assertFileHasContent(DO_SKIP, '10.11.12.13') + self.assertFileHasContent(DO_SKIP, '6.0.0.1') + + def test_incorrect_version_file_not_skipped(self): + self.assertFileCollected(NO_SKIP) + self.assertFileNotHasContent(NO_SKIP, '10.11.12.13') + self.assertFileNotHasContent(NO_SKIP, '6.0.0.1') diff --git a/tests/test_data/fake_plugins/skip_versions.py b/tests/test_data/fake_plugins/skip_versions.py new file mode 100644 index 00000000..e8a1d533 --- /dev/null +++ b/tests/test_data/fake_plugins/skip_versions.py @@ -0,0 +1,24 @@ +# 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.report.plugins import Plugin, IndependentPlugin + + +class SkipVersions(Plugin, IndependentPlugin): + """Collect the fake version files from the test suite, to ensure proper + skipping of version files + """ + + plugin_name = 'skip_versions' + short_desc = 'fake plugin to test skipping version files via the IP parser' + + def setup(self): + self.add_copy_spec([ + '/tmp/sos-test-version.txt', + '/tmp/sos-test-version-noskip' + ]) diff --git a/tests/test_data/tmp/sos-test-version-noskip b/tests/test_data/tmp/sos-test-version-noskip new file mode 100644 index 00000000..bc5558de --- /dev/null +++ b/tests/test_data/tmp/sos-test-version-noskip @@ -0,0 +1,6 @@ +This is a test file for skipping version files with the IP parser. + +All dotted-quad strings SHOULD be changed in this file. + +10.11.12.13 +6.0.0.1 diff --git a/tests/test_data/tmp/sos-test-version.txt b/tests/test_data/tmp/sos-test-version.txt new file mode 100644 index 00000000..62a96e57 --- /dev/null +++ b/tests/test_data/tmp/sos-test-version.txt @@ -0,0 +1,6 @@ +This is a test file for skipping version files with the IP parser. + +No dotted-quad strings should be changed in this file. + +10.11.12.13 +6.0.0.1 -- cgit