From 94762f1f167b64a1e9b0103a54ed9740f154dabc Mon Sep 17 00:00:00 2001 From: Mark Huth Date: Tue, 12 Apr 2022 15:23:47 +1000 Subject: [PATCH] Skip malware-detection tests on RHEL6/python2.6 (not supported) Signed-off-by: Mark Huth --- .../tests/client/apps/test_malware_detection.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/insights/tests/client/apps/test_malware_detection.py b/insights/tests/client/apps/test_malware_detection.py index 3e63b0416f..df4a991aad 100644 --- a/insights/tests/client/apps/test_malware_detection.py +++ b/insights/tests/client/apps/test_malware_detection.py @@ -1,5 +1,7 @@ import os import re +import sys + import pytest import yaml import time @@ -54,6 +56,10 @@ # Run the test_processes_scan_since test? TEST_PROCESSES_SCAN_SINCE = getenv_bool("TEST_PROCESSES_SCAN_SINCE", False) +# Are we running on RHEL6? (well actually, with python 2.6) +IS_RHEL6 = sys.version_info < (2, 7) +SKIP_IF_RHEL6_REASON = "The malware-detection client isn't supported on RHEL6 / python 2.6" + @pytest.fixture def create_test_files(): @@ -84,6 +90,7 @@ def extract_tmp_files(): os.system('rm -rf %s' % TEMP_TEST_DIR) +@pytest.mark.skipif(IS_RHEL6, reason=SKIP_IF_RHEL6_REASON) class TestDefaultValues: def test_default_spec(self): # Read in the default malware spec and check its values @@ -155,6 +162,7 @@ def test_running_default_options(self, log_mock, yara, rules, cmd, create_test_f assert re.search('metadata:.*process_name', mutation) +@pytest.mark.skipif(IS_RHEL6, reason=SKIP_IF_RHEL6_REASON) @patch(BUILD_YARA_COMMAND_TARGET) @patch(GET_RULES_TARGET, return_value=RULES_FILE) @patch(LOAD_CONFIG_TARGET, return_value=CONFIG) @@ -223,6 +231,7 @@ def test_invalid_yara_versions(self, version_mock, exists_mock, log_mock, conf, # Use patch.object, just because I wanted to try using patch.object instead of using patch all the time :shrug: +@pytest.mark.skipif(IS_RHEL6, reason=SKIP_IF_RHEL6_REASON) @patch('os.remove') # Mock os.remove so it doesn't actually try to remove any existing files @patch.object(InsightsConnection, 'get', return_value=Mock(status_code=200, content=b"Rule Content")) @patch.object(InsightsConnection, 'get_proxies') @@ -382,6 +391,7 @@ def test_via_satellite_proxy(self, log_mock, conf, yara, cmd, session, proxies, log_mock.debug.assert_called_with("Downloading rules from: %s", replaced_url) +@pytest.mark.skipif(IS_RHEL6, reason=SKIP_IF_RHEL6_REASON) @patch(GET_RULES_TARGET, return_value=RULES_FILE) @patch(FIND_YARA_TARGET, return_value=YARA) @patch(LOAD_CONFIG_TARGET, return_value=CONFIG) @@ -439,6 +449,7 @@ def test_build_yara_command_fail(self, size_mock, log_mock, conf, yara, rules): log_mock.error.assert_called_with("Unable to use rules file %s: %s", RULES_FILE, "invalid") +@pytest.mark.skipif(IS_RHEL6, reason=SKIP_IF_RHEL6_REASON) @patch(BUILD_YARA_COMMAND_TARGET) @patch(GET_RULES_TARGET, return_value=RULES_FILE) @patch(FIND_YARA_TARGET, return_value=YARA) @@ -975,6 +986,7 @@ def test_processes_scan_options_invalid_or_missing_values(self, log_mock, yara, log_mock.error.assert_any_call("Unable to find the items specified for the processes_scan_exclude option. Skipping ...") +@pytest.mark.skipif(IS_RHEL6, reason=SKIP_IF_RHEL6_REASON) @patch(BUILD_YARA_COMMAND_TARGET) @patch(GET_RULES_TARGET, return_value=TEST_RULE_FILE) @patch(FIND_YARA_TARGET, return_value=YARA) @@ -1110,6 +1122,7 @@ def test_processes_scan_since(self, log_mock, yara, rules, cmd, create_test_file assert len(mdc.scan_pids) == 1 +@pytest.mark.skipif(IS_RHEL6, reason=SKIP_IF_RHEL6_REASON) @patch('os.remove') # Mock os.remove so it doesn't actually try to remove any existing files @patch(BUILD_YARA_COMMAND_TARGET) @patch(FIND_YARA_TARGET, return_value=YARA) @@ -1291,6 +1304,7 @@ def test_rule_n_glob_files_excluded(self, conf, log_mock, yara, cmd, remove, ext assert all([f not in mdc.filesystem_scan_exclude_list for f in glob_files]) +@pytest.mark.skipif(IS_RHEL6, reason=SKIP_IF_RHEL6_REASON) class TestFilesystemIncludeExcludeMethods: def test_toplevel_dirs(self): @@ -1424,6 +1438,7 @@ def test_process_exclude_items(self): assert processed_items == get_toplevel_dirs() +@pytest.mark.skipif(IS_RHEL6, reason=SKIP_IF_RHEL6_REASON) @patch(BUILD_YARA_COMMAND_TARGET) @patch(GET_RULES_TARGET, return_value=RULES_FILE) @patch(FIND_YARA_TARGET, return_value=YARA) @@ -1543,6 +1558,7 @@ def test_process_include_exclude_tmp_files(self, conf, yara, rules, cmd, extract assert all([x not in scan_dict['/tmp']['include'] for x in dont_include_files]) +@pytest.mark.skipif(IS_RHEL6, reason=SKIP_IF_RHEL6_REASON) @patch(BUILD_YARA_COMMAND_TARGET) @patch(GET_RULES_TARGET, return_value=RULES_FILE) @patch(FIND_YARA_TARGET, return_value=YARA)