Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip malware-detection tests on RHEL6/python2.6 (not supported) #3382

Merged
merged 1 commit into from
Apr 21, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions insights/tests/client/apps/test_malware_detection.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import os
import re
import sys

import pytest
import yaml
import time
Expand Down Expand Up @@ -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():
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down