diff --git a/tests/integration/test_fim/test_files/test_basic_usage/data/wazuh_conf.yaml b/tests/integration/test_fim/test_files/test_basic_usage/data/wazuh_conf.yaml index a7d2a19349..9d67a6f4e3 100644 --- a/tests/integration/test_fim/test_files/test_basic_usage/data/wazuh_conf.yaml +++ b/tests/integration/test_fim/test_files/test_basic_usage/data/wazuh_conf.yaml @@ -1,32 +1,60 @@ ---- -# conf 1 -- tags: - - ossec_conf - apply_to_modules: - - MODULE_NAME - sections: - - section: syscheck - elements: - - disabled: - value: 'no' - - directories: - value: TEST_DIRECTORIES - attributes: - - check_all: 'yes' - - FIM_MODE - -# conf 2 -- tags: - - ossec_conf_wildcards - apply_to_modules: - - MODULE_NAME - sections: - - section: syscheck - elements: - - disabled: - value: 'no' - - directories: - value: TEST_WILDCARDS - attributes: - - check_all: 'yes' - - FIM_MODE +--- +# conf 1 +- tags: + - ossec_conf + apply_to_modules: + - MODULE_NAME + sections: + - section: syscheck + elements: + - disabled: + value: 'no' + - directories: + value: TEST_DIRECTORIES + attributes: + - check_all: 'yes' + - FIM_MODE + - section: sca + elements: + - enabled: + value: 'no' + - section: rootcheck + elements: + - disabled: + value: 'yes' + - section: wodle + attributes: + - name: 'syscollector' + elements: + - disabled: + value: 'yes' + +# conf 2 +- tags: + - ossec_conf_wildcards + apply_to_modules: + - MODULE_NAME + sections: + - section: syscheck + elements: + - disabled: + value: 'no' + - directories: + value: TEST_WILDCARDS + attributes: + - check_all: 'yes' + - FIM_MODE + - section: sca + elements: + - enabled: + value: 'no' + - section: rootcheck + elements: + - disabled: + value: 'yes' + - section: wodle + attributes: + - name: 'syscollector' + elements: + - disabled: + value: 'yes' diff --git a/tests/integration/test_fim/test_files/test_basic_usage/data/wazuh_conf_check_inodes.yaml b/tests/integration/test_fim/test_files/test_basic_usage/data/wazuh_conf_check_inodes.yaml index 3a3aec654f..b9d005bc5c 100644 --- a/tests/integration/test_fim/test_files/test_basic_usage/data/wazuh_conf_check_inodes.yaml +++ b/tests/integration/test_fim/test_files/test_basic_usage/data/wazuh_conf_check_inodes.yaml @@ -1,18 +1,32 @@ ---- -# conf 1 -- tags: - - ossec_conf - apply_to_modules: - - MODULE_NAME - sections: - - section: syscheck - elements: - - disabled: - value: 'no' - - directories: - value: TEST_DIRECTORIES - attributes: - - FIM_MODE - - check_all: 'yes' - - check_mtime: CHECK_TYPE - - check_inode: CHECK_TYPE +--- +# conf 1 +- tags: + - ossec_conf + apply_to_modules: + - MODULE_NAME + sections: + - section: syscheck + elements: + - disabled: + value: 'no' + - directories: + value: TEST_DIRECTORIES + attributes: + - FIM_MODE + - check_all: 'yes' + - check_mtime: CHECK_TYPE + - check_inode: CHECK_TYPE + - section: sca + elements: + - enabled: + value: 'no' + - section: rootcheck + elements: + - disabled: + value: 'yes' + - section: wodle + attributes: + - name: 'syscollector' + elements: + - disabled: + value: 'yes' diff --git a/tests/integration/test_fim/test_files/test_basic_usage/data/wazuh_conf_disabled.yaml b/tests/integration/test_fim/test_files/test_basic_usage/data/wazuh_conf_disabled.yaml index 8293c9a076..5edebc48de 100644 --- a/tests/integration/test_fim/test_files/test_basic_usage/data/wazuh_conf_disabled.yaml +++ b/tests/integration/test_fim/test_files/test_basic_usage/data/wazuh_conf_disabled.yaml @@ -1,15 +1,29 @@ ---- -# conf 1 -- tags: - - disabled_conf - apply_to_modules: - - test_basic_usage_disabled - sections: - - section: syscheck - elements: - - disabled: - value: 'yes' - - directories: - value: TEST_DIRECTORIES - attributes: - - FIM_MODE +--- +# conf 1 +- tags: + - disabled_conf + apply_to_modules: + - test_basic_usage_disabled + sections: + - section: syscheck + elements: + - disabled: + value: 'yes' + - directories: + value: TEST_DIRECTORIES + attributes: + - FIM_MODE + - section: sca + elements: + - enabled: + value: 'no' + - section: rootcheck + elements: + - disabled: + value: 'yes' + - section: wodle + attributes: + - name: 'syscollector' + elements: + - disabled: + value: 'yes' diff --git a/tests/integration/test_fim/test_files/test_basic_usage/data/wazuh_conf_new_dirs.yaml b/tests/integration/test_fim/test_files/test_basic_usage/data/wazuh_conf_new_dirs.yaml index 4da57275d7..9cd56373f9 100644 --- a/tests/integration/test_fim/test_files/test_basic_usage/data/wazuh_conf_new_dirs.yaml +++ b/tests/integration/test_fim/test_files/test_basic_usage/data/wazuh_conf_new_dirs.yaml @@ -1,18 +1,32 @@ ---- -# conf 1 -- tags: - - ossec_conf - apply_to_modules: - - MODULE_NAME - sections: - - section: syscheck - elements: - - disabled: - value: 'no' - - frequency: - value: 30 - - directories: - value: TEST_DIRECTORIES - attributes: - - check_all: 'yes' - - FIM_MODE +--- +# conf 1 +- tags: + - ossec_conf + apply_to_modules: + - MODULE_NAME + sections: + - section: syscheck + elements: + - disabled: + value: 'no' + - frequency: + value: 30 + - directories: + value: TEST_DIRECTORIES + attributes: + - check_all: 'yes' + - FIM_MODE + - section: sca + elements: + - enabled: + value: 'no' + - section: rootcheck + elements: + - disabled: + value: 'yes' + - section: wodle + attributes: + - name: 'syscollector' + elements: + - disabled: + value: 'yes' diff --git a/tests/integration/test_fim/test_files/test_basic_usage/data/wazuh_conf_new_dirs_win32.yaml b/tests/integration/test_fim/test_files/test_basic_usage/data/wazuh_conf_new_dirs_win32.yaml index 1e89512491..218b6c799a 100644 --- a/tests/integration/test_fim/test_files/test_basic_usage/data/wazuh_conf_new_dirs_win32.yaml +++ b/tests/integration/test_fim/test_files/test_basic_usage/data/wazuh_conf_new_dirs_win32.yaml @@ -1,20 +1,34 @@ ---- -# conf 1 -- tags: - - ossec_conf - apply_to_modules: - - MODULE_NAME - sections: - - section: syscheck - elements: - - disabled: - value: 'no' - - frequency: - value: 30 - - windows_audit_interval: - value: WINDOWS_AUDIT_INTERVAL - - directories: - value: TEST_DIRECTORIES - attributes: - - check_all: 'yes' - - FIM_MODE +--- +# conf 1 +- tags: + - ossec_conf + apply_to_modules: + - MODULE_NAME + sections: + - section: syscheck + elements: + - disabled: + value: 'no' + - frequency: + value: 30 + - windows_audit_interval: + value: WINDOWS_AUDIT_INTERVAL + - directories: + value: TEST_DIRECTORIES + attributes: + - check_all: 'yes' + - FIM_MODE + - section: sca + elements: + - enabled: + value: 'no' + - section: rootcheck + elements: + - disabled: + value: 'yes' + - section: wodle + attributes: + - name: 'syscollector' + elements: + - disabled: + value: 'yes' diff --git a/tests/integration/test_fim/test_files/test_basic_usage/data/wazuh_conf_win32.yaml b/tests/integration/test_fim/test_files/test_basic_usage/data/wazuh_conf_win32.yaml index e211802f25..0ea2c7d4bd 100644 --- a/tests/integration/test_fim/test_files/test_basic_usage/data/wazuh_conf_win32.yaml +++ b/tests/integration/test_fim/test_files/test_basic_usage/data/wazuh_conf_win32.yaml @@ -1,18 +1,32 @@ ---- -# conf 1 -- tags: - - ossec_conf - apply_to_modules: - - MODULE_NAME - sections: - - section: syscheck - elements: - - disabled: - value: 'no' - - windows_audit_interval: - value: WINDOWS_AUDIT_INTERVAL - - directories: - value: TEST_DIRECTORIES - attributes: - - check_all: 'yes' - - FIM_MODE +--- +# conf 1 +- tags: + - ossec_conf + apply_to_modules: + - MODULE_NAME + sections: + - section: syscheck + elements: + - disabled: + value: 'no' + - windows_audit_interval: + value: WINDOWS_AUDIT_INTERVAL + - directories: + value: TEST_DIRECTORIES + attributes: + - check_all: 'yes' + - FIM_MODE + - section: sca + elements: + - enabled: + value: 'no' + - section: rootcheck + elements: + - disabled: + value: 'yes' + - section: wodle + attributes: + - name: 'syscollector' + elements: + - disabled: + value: 'yes' diff --git a/tests/integration/test_fim/test_files/test_basic_usage/test_basic_usage_no_dir.py b/tests/integration/test_fim/test_files/test_basic_usage/test_basic_usage_no_dir.py index 7a3649e436..71a77a1c17 100644 --- a/tests/integration/test_fim/test_files/test_basic_usage/test_basic_usage_no_dir.py +++ b/tests/integration/test_fim/test_files/test_basic_usage/test_basic_usage_no_dir.py @@ -1,74 +1,75 @@ -# Copyright (C) 2015-2021, Wazuh Inc. -# Created by Wazuh, Inc. . -# This program is free software; you can redistribute it and/or modify it under the terms of GPLv2 - -import os - -import pytest -from wazuh_testing import global_parameters -from wazuh_testing.fim import LOG_FILE_PATH, generate_params, callback_empty_directories -from wazuh_testing.tools import PREFIX -from wazuh_testing.tools.configuration import load_wazuh_configurations, check_apply_test -from wazuh_testing.tools.monitoring import FileMonitor - -# Marks - -pytestmark = pytest.mark.tier(level=0) - -# Variables - -test_directories = [] -testdir = os.path.join(PREFIX, 'testdir1') -test_data_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'data') -configurations_path = os.path.join(test_data_path, 'wazuh_conf.yaml') -wazuh_log_monitor = FileMonitor(LOG_FILE_PATH) - -# Configurations - -p, m = generate_params(extra_params={'TEST_DIRECTORIES': '', 'MODULE_NAME': __name__}) -configuration1 = load_wazuh_configurations(configurations_path, __name__, params=p, metadata=m) - -p, m = generate_params(extra_params={'TEST_DIRECTORIES': testdir, 'MODULE_NAME': __name__}) -configuration2 = load_wazuh_configurations(configurations_path, __name__, params=p, metadata=m) - -# Merge both list of configurations into the final one to avoid skips and configuration issues -configurations = configuration1 + configuration2 - - -# Fixtures - -@pytest.fixture(scope='module', params=configurations) -def get_configuration(request): - """Get configurations from the module.""" - return request.param - - -# Tests - -@pytest.mark.parametrize('tags_to_apply', [ - {'ossec_conf'} -]) -def test_new_directory(tags_to_apply, get_configuration, configure_environment, restart_syscheckd): - """Verify that syscheck shows a debug message when an empty directories tag is found. - - Parameters - ---------- - tags_to_apply : set - Run test if matches with a configuration identifier, skip otherwise - """ - check_apply_test(tags_to_apply, get_configuration['tags']) - - # Check that the warning is displayed when there is no directory. - for section in get_configuration['sections']: - if not section['elements'][1]['directories']['value']: - wazuh_log_monitor.start(timeout=global_parameters.default_timeout, - callback=callback_empty_directories, - error_message='Did not receive expected ' - '"DEBUG: (6338): Empty directories tag found in the configuration" ' - 'event').result() - # Check that the message is not displayed when the directory is specified. - else: - with pytest.raises(TimeoutError): - event = wazuh_log_monitor.start(timeout=global_parameters.default_timeout, - callback=callback_empty_directories).result() - raise AttributeError(f'Unexpected event {event}') +# Copyright (C) 2015-2021, Wazuh Inc. +# Created by Wazuh, Inc. . +# This program is free software; you can redistribute it and/or modify it under the terms of GPLv2 + +import os + +import pytest +from wazuh_testing import global_parameters +from wazuh_testing.fim import LOG_FILE_PATH, generate_params, callback_empty_directories +from wazuh_testing.tools import PREFIX +from wazuh_testing.tools.configuration import load_wazuh_configurations, check_apply_test +from wazuh_testing.tools.monitoring import FileMonitor + +# Marks + +pytestmark = pytest.mark.tier(level=0) + +# Variables + +test_directories = [] +testdir = os.path.join(PREFIX, 'testdir1') +test_data_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'data') +configurations_path = os.path.join(test_data_path, 'wazuh_conf.yaml') +wazuh_log_monitor = FileMonitor(LOG_FILE_PATH) + +# Configurations + +p, m = generate_params(extra_params={'TEST_DIRECTORIES': '', 'MODULE_NAME': __name__}) +configuration1 = load_wazuh_configurations(configurations_path, __name__, params=p, metadata=m) + +p, m = generate_params(extra_params={'TEST_DIRECTORIES': testdir, 'MODULE_NAME': __name__}) +configuration2 = load_wazuh_configurations(configurations_path, __name__, params=p, metadata=m) + +# Merge both list of configurations into the final one to avoid skips and configuration issues +configurations = configuration1 + configuration2 + + +# Fixtures + +@pytest.fixture(scope='module', params=configurations) +def get_configuration(request): + """Get configurations from the module.""" + return request.param + + +# Tests + +@pytest.mark.parametrize('tags_to_apply', [ + {'ossec_conf'} +]) +def test_new_directory(tags_to_apply, get_configuration, configure_environment, restart_syscheckd): + """Verify that syscheck shows a debug message when an empty directories tag is found. + + Parameters + ---------- + tags_to_apply : set + Run test if matches with a configuration identifier, skip otherwise + """ + check_apply_test(tags_to_apply, get_configuration['tags']) + + # Check that the warning is displayed when there is no directory. + for section in get_configuration['sections']: + if section['section'] == 'syscheck': + if not section['elements'][1]['directories']['value']: + wazuh_log_monitor.start(timeout=global_parameters.default_timeout, + callback=callback_empty_directories, + error_message='Did not receive expected ' + '"DEBUG: (6338): Empty directories tag found in the configuration" ' + 'event').result() + # Check that the message is not displayed when the directory is specified. + else: + with pytest.raises(TimeoutError): + event = wazuh_log_monitor.start(timeout=global_parameters.default_timeout, + callback=callback_empty_directories).result() + raise AttributeError(f'Unexpected event {event}')