From 6531515e6b58f7f1986dc1420f460397de25f885 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Rebollo?= Date: Fri, 3 Sep 2021 13:53:58 +0200 Subject: [PATCH 01/27] Create configure_local_internal_options_module fixture --- .../wazuh_testing/tools/__init__.py | 71 +++++++++++++-- .../wazuh_testing/tools/configuration.py | 91 ++++++++++++++++++- tests/integration/conftest.py | 54 ++++++++++- 3 files changed, 205 insertions(+), 11 deletions(-) diff --git a/deps/wazuh_testing/wazuh_testing/tools/__init__.py b/deps/wazuh_testing/wazuh_testing/tools/__init__.py index 6538261ac7..811fb23fe2 100644 --- a/deps/wazuh_testing/wazuh_testing/tools/__init__.py +++ b/deps/wazuh_testing/wazuh_testing/tools/__init__.py @@ -3,13 +3,14 @@ # This program is free software; you can redistribute it and/or modify it under the terms of GPLv2 import os -import sys import platform import subprocess +import sys if sys.platform == 'win32': WAZUH_PATH = os.path.join("C:", os.sep, "Program Files (x86)", "ossec-agent") WAZUH_CONF = os.path.join(WAZUH_PATH, 'ossec.conf') + WAZUH_LOCAL_INTERNAL_OPTIONS = os.path.join(WAZUH_PATH, 'local_internal_options.conf') WAZUH_SOURCES = os.path.join('/', 'wazuh') LOG_FILE_PATH = os.path.join(WAZUH_PATH, 'ossec.log') PREFIX = os.path.join('c:', os.sep) @@ -21,8 +22,6 @@ LOGCOLLECTOR_STATISTICS_FILE = os.path.join(WAZUH_PATH, 'wazuh-logcollector.state') REMOTE_STATISTICS_FILE = None ANALYSIS_STATISTICS_FILE = None - UPGRADE_PATH = os.path.join(WAZUH_PATH, 'upgrade') - else: @@ -38,7 +37,7 @@ PREFIX = os.sep WAZUH_CONF_RELATIVE = os.path.join('etc', 'ossec.conf') - + WAZUH_LOCAL_INTERNAL_OPTIONS = os.path.join(f'{WAZUH_PATH}/etc', 'local_internal_options.conf') WAZUH_CONF = os.path.join(WAZUH_PATH, WAZUH_CONF_RELATIVE) WAZUH_API_CONF = os.path.join(WAZUH_PATH, 'api', 'configuration', 'api.yaml') WAZUH_SECURITY_CONF = os.path.join(WAZUH_PATH, 'api', 'configuration', 'security', 'security.yaml') @@ -49,14 +48,13 @@ LOGCOLLECTOR_STATISTICS_FILE = os.path.join(WAZUH_PATH, 'var', 'run', 'wazuh-logcollector.state') REMOTE_STATISTICS_FILE = os.path.join(WAZUH_PATH, 'var', 'run', 'wazuh-remoted.state') ANALYSIS_STATISTICS_FILE = os.path.join(WAZUH_PATH, 'var', 'run', 'wazuh-analysisd.state') - UPGRADE_PATH = os.path.join(WAZUH_PATH, 'var', 'upgrade') try: import grp import pwd - OSSEC_UID = pwd.getpwnam("ossec").pw_uid - OSSEC_GID = grp.getgrnam("ossec").gr_gid + WAZUH_UID = pwd.getpwnam("wazuh").pw_uid + WAZUH_GID = grp.getgrnam("wazuh").gr_gid except (ImportError, KeyError, ModuleNotFoundError): pass @@ -86,7 +84,15 @@ def get_service(): return 'wazuh-manager' if service == 'server' else 'wazuh-agent' -_data_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'data') +_data_path = os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))), 'data') + +CLIENT_KEYS_PATH = os.path.join(WAZUH_PATH, 'etc', 'client.keys') +SERVER_KEY_PATH = os.path.join(WAZUH_PATH, 'etc', 'manager.key') +SERVER_CERT_PATH = os.path.join(WAZUH_PATH, 'etc', 'manager.cert') + +CLIENT_CUSTOM_KEYS_PATH = os.path.join(_data_path, 'sslmanager.key') +CLIENT_CUSTOM_CERT_PATH = os.path.join(_data_path, 'sslmanager.cert') + WAZUH_LOGS_PATH = os.path.join(WAZUH_PATH, 'logs') ALERT_FILE_PATH = os.path.join(WAZUH_LOGS_PATH, 'alerts', 'alerts.json') CLUSTER_LOGS_PATH = os.path.join(WAZUH_LOGS_PATH, 'cluster.log') @@ -111,10 +117,13 @@ def get_service(): MODULESD_CONTROL_SOCKET_PATH = os.path.join(QUEUE_SOCKETS_PATH, 'control') MODULESD_KREQUEST_SOCKET_PATH = os.path.join(QUEUE_SOCKETS_PATH, 'krequest') MODULESD_C_INTERNAL_SOCKET_PATH = os.path.join(CLUSTER_SOCKET_PATH, 'c-internal.sock') -ACTIVE_RESPONSE_SOCKET_PATH = os.path.join(QUEUE_ALERTS_PATH,'ar') +ACTIVE_RESPONSE_SOCKET_PATH = os.path.join(QUEUE_ALERTS_PATH, 'ar') WAZUH_SOCKETS = { 'wazuh-agentd': [], + 'wazuh-apid': [], + 'wazuh-agentlessd': [], + 'wazuh-csyslogd': [], 'wazuh-analysisd': [ ANALYSISD_ANALISIS_SOCKET_PATH, ANALYSISD_QUEUE_SOCKET_PATH @@ -124,6 +133,7 @@ def get_service(): 'wazuh-logcollector': [LOGCOLLECTOR_SOCKET_PATH], 'wazuh-monitord': [MONITORD_SOCKET_PATH], 'wazuh-remoted': [REMOTED_SOCKET_PATH], + 'wazuh-maild': [], 'wazuh-syscheckd': [SYSCHECKD_SOCKET_PATH], 'wazuh-db': [WAZUH_DB_SOCKET_PATH], 'wazuh-modulesd': [ @@ -140,3 +150,46 @@ def get_service(): MODULESD_KREQUEST_SOCKET_PATH, AUTHD_SOCKET_PATH ] + +# Wazuh daemons +LOGCOLLECTOR_DAEMON = 'wazuh-logcollector' +AGENTLESS_DAEMON = 'wazuh-agentlessd' +CSYSLOG_DAEMON = 'wazuh-csyslogd' +REMOTE_DAEMON = 'wazuh-remoted' +ANALYSISD_DAEMON = 'wazuh-analysisd' +API_DAEMON = 'wazuh-apid' +MAIL_DAEMON = 'wazuh-maild' +SYSCHECK_DAEMON = 'wazuh-syscheckd' +EXEC_DAEMON = 'wazuh-execd' +MODULES_DAEMON = 'wazuh-modulesd' +CLUSTER_DAEMON = 'wazuh-clusterd' +INTEGRATOR_DAEMON = 'wazuh-integratord' +MONITOR_DAEMON = 'wazuh-monitord' +DB_DAEMON = 'wazuh-db' +AGENT_DAEMON = 'wazuh-agentd' + + +ALL_MANAGER_DAEMONS = [LOGCOLLECTOR_DAEMON, AGENTLESS_DAEMON, CSYSLOG_DAEMON, REMOTE_DAEMON, ANALYSISD_DAEMON, + API_DAEMON, MAIL_DAEMON, SYSCHECK_DAEMON, EXEC_DAEMON, MODULES_DAEMON, CLUSTER_DAEMON, + INTEGRATOR_DAEMON, MONITOR_DAEMON, DB_DAEMON] +ALL_AGENT_DAEMONS = [AGENT_DAEMON, EXEC_DAEMON, LOGCOLLECTOR_DAEMON, SYSCHECK_DAEMON, MODULES_DAEMON] +API_DAEMONS_REQUIREMENTS = [API_DAEMON, MODULES_DAEMON, ANALYSISD_DAEMON, EXEC_DAEMON, DB_DAEMON, REMOTE_DAEMON] + + +DISABLE_MONITORD_ROTATE_LOG_OPTION = {'monitord.rotate_log': '0'} +REMOTED_LOCAL_INTERNAL_OPTIONS = {'remoted.debug': '2'}.update(DISABLE_MONITORD_ROTATE_LOG_OPTION) +ANALYSISD_LOCAL_INTERNAL_OPTIONS = {'analysisd.debug': '2'}.update(DISABLE_MONITORD_ROTATE_LOG_OPTION) +AGENTD_LOCAL_INTERNAL_OPTIONS = {'agent.debug': '2', 'execd': '2'}.update(DISABLE_MONITORD_ROTATE_LOG_OPTION) +FIM_LOCAL_INTERNAL_OPTIONS_MANAGER = {'syscheck.debug': '2', + 'analysisd.debug': '2'}.update(DISABLE_MONITORD_ROTATE_LOG_OPTION) +FIM_LOCAL_INTERNAL_OPTIONS_AGENT_UNIX = {'syscheck.debug': '2', + 'agent.debug': '2'}.update(DISABLE_MONITORD_ROTATE_LOG_OPTION) +FIM_LOCAL_INTERNAL_OPTIONS_AGENT_WINDOWS = {'syscheck.debug': '2', + 'windows.debug': '2'}.update(DISABLE_MONITORD_ROTATE_LOG_OPTION) +GCLOUD_LOCAL_INTERNAL_OPTIONS = {'analysisd.debug': '2', + 'wazuh_modules.debug': '2'}.update(DISABLE_MONITORD_ROTATE_LOG_OPTION) +LOGTEST_LOCAL_INTERNAL_OPTIONS = {'analysisd.debug': '2'} +REMOTED_LOCAL_INTERNAL_OPTIONS = {'remoted.debug': '2', 'wazuh_database.interval': '2', 'wazuh_db.commit_time': '2', + 'wazuh_db.commit_time_max': '3'}.update(DISABLE_MONITORD_ROTATE_LOG_OPTION) +VD_LOCAL_INTERNAL_OPTIONS = {'wazuh_modules.debug': '2'}.update(DISABLE_MONITORD_ROTATE_LOG_OPTION) +WPK_LOCAL_INTERNAL_OPTIONS = {'wazuh_modules.debug': '2'} diff --git a/deps/wazuh_testing/wazuh_testing/tools/configuration.py b/deps/wazuh_testing/wazuh_testing/tools/configuration.py index e3e231f068..bd06c1acb2 100644 --- a/deps/wazuh_testing/wazuh_testing/tools/configuration.py +++ b/deps/wazuh_testing/wazuh_testing/tools/configuration.py @@ -12,7 +12,7 @@ import pytest import yaml from wazuh_testing import global_parameters -from wazuh_testing.tools import WAZUH_PATH, GEN_OSSEC, WAZUH_CONF, PREFIX +from wazuh_testing.tools import WAZUH_PATH, GEN_OSSEC, WAZUH_CONF, PREFIX, WAZUH_LOCAL_INTERNAL_OPTIONS # customize _serialize_xml to avoid lexicographical order in XML attributes @@ -540,3 +540,92 @@ def generate_syscheck_registry_config(): for yn_values, tag_value in itertools.product(values_list, tags): yn_str = ' '.join([f'{name}="{value}"' for name, value in zip(check_names, yn_values)]) yield ' '.join([yn_str, tag_value]) + + +def get_wazuh_local_internal_options() -> List[str]: + """Get current `internal_options.conf` file content. + + Returns + List of str: A list containing all the lines of the `ossec.conf` file. + """ + with open(WAZUH_LOCAL_INTERNAL_OPTIONS) as f: + lines = f.readlines() + return lines + + +def set_wazuh_local_internal_options(wazuh_local_internal_options: List[str]): + """Set up Wazuh `local_internal_options.conf` file content. + + Returns + List of str: A list containing all the lines of the `local_interal_options.conf` file. + """ + with open(WAZUH_LOCAL_INTERNAL_OPTIONS, 'w') as f: + f.writelines(wazuh_local_internal_options) + + +def add_wazuh_local_internal_options(wazuh_local_internal_options_dict): + """Add new local internal options to the current configuration. + + Args: + wazuh_local_internal_options_dict (List of str): A list containing local internal options to add. + """ + local_internal_options_str = create_local_internal_options(wazuh_local_internal_options_dict) + with open(WAZUH_LOCAL_INTERNAL_OPTIONS, 'a') as f: + f.writelines(local_internal_options_str) + + +def create_local_internal_options(dict_local_internal_options): + """Create local_internal_options using a dictionary. + + Args: + dict_local_internal_options (dict) : Dictionary with the local internal options + """ + wazuh_local_internal_options = '' + for key, value in dict_local_internal_options.items(): + wazuh_local_internal_options += f"{str(key)}={str(value)}\n" + return wazuh_local_internal_options + + +def local_internal_options_to_dict(local_internal_options): + """ Create a dictionary with current local internal options. + + Args: + local_internal_options (List of str): A list containing local internal options. + """ + dict_local_internal_options= {} + no_comments_options = [line.strip() for line in local_internal_options + if not (line.startswith('#') or line == '\n')] + for line in no_comments_options: + key, value = line.split('=') + dict_local_internal_options[key.rstrip("\n")] = value + + return dict_local_internal_options + + +def get_local_internal_options_dict(): + """Return the local internal options in a dictionary + + Returns: + dict: Local internal options. + """ + local_internal_option_dict = {} + with open(WAZUH_LOCAL_INTERNAL_OPTIONS, 'r') as local_internal_option_file: + configuration_options = local_internal_option_file.readlines() + for configuration_option in configuration_options: + if not configuration_option.startswith('#'): + option_name, option_value = configuration_option.split('=') + local_internal_option_dict[option_name] = option_value + + return local_internal_option_dict + + +def set_local_internal_options_dict(dict_local_internal_options): + """Set the local internal options using a dictionary + + Args: + local_internal_options_dict (dict): A dictionary containing local internal options. + """ + with open(WAZUH_LOCAL_INTERNAL_OPTIONS, 'w') as local_internal_option_file: + for option_name, option_value in dict_local_internal_options.items(): + local_internal_configuration_string = f"{str(option_name)}={str(option_value)}\n" + local_internal_option_file.write(local_internal_configuration_string) diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index 27cbbcff78..dbdcba25bb 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -14,7 +14,10 @@ import pytest from numpydoc.docscrape import FunctionDoc from py.xml import html -from wazuh_testing import global_parameters + +import wazuh_testing.tools.configuration as conf +from wazuh_testing import global_parameters, logger +from wazuh_testing.logcollector import create_file_structure, delete_file_structure from wazuh_testing.tools import LOG_FILE_PATH, WAZUH_CONF, get_service, ALERT_FILE_PATH from wazuh_testing.tools.configuration import get_wazuh_conf, set_section_wazuh_conf, write_wazuh_conf from wazuh_testing.tools.file import truncate_file @@ -574,3 +577,52 @@ def put_env_variables(get_configuration, request): for env in environment_variables: if sys.platform != 'win32': os.unsetenv(env[0]) + + +@pytest.fixture(scope="module") +def create_file_structure_module(get_files_list): + """Module scope version of create_file_structure.""" + create_file_structure(get_files_list) + + yield + + delete_file_structure(get_files_list) + + +@pytest.fixture(scope="function") +def create_file_structure_function(get_files_list): + """Function scope version of create_file_structure.""" + create_file_structure(get_files_list) + + yield + + delete_file_structure(get_files_list) + + +@pytest.fixture(scope="module") +def configure_local_internal_options_module(request): + """Fixture to configure the local internal options file. + + It uses the test variable local_internal_options. This should be + a dictionary wich keys and values corresponds to the internal option configuration, For example: + local_internal_options = ['monitord.rotate_log': '0', 'syscheck.debug': '0' ] + """ + try: + local_internal_options = getattr(request.module, 'local_internal_options', []) + except AttributeError as local_internal_configuration_not_set: + logger.error('Configure Local Internal Options: Error - local_internal_options is not set') + raise local_internal_configuration_not_set + + + backup_local_internal_options = conf.get_local_internal_options_dict() + + logger.error('Configure Local Internal Options: DEBUG - Set local_internal_option to ' + + f"{str(local_internal_options)}") + conf.set_local_internal_options_dict(local_internal_options) + + yield + + + logger.error('Configure Local Internal Options: DEBUG - Restore local_internal_option to ' + + f"{str(backup_local_internal_options)}") + conf.set_local_internal_options_dict(backup_local_internal_options) From 004d938dcd9e61133b80efc3aa0a85f140285dda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Rebollo?= Date: Fri, 3 Sep 2021 14:45:27 +0200 Subject: [PATCH 02/27] Fix minnor style errors in configure_local_internal fixture Define default internal_option_configurations for wazuh daemons --- .../wazuh_testing/tools/__init__.py | 35 ++++--------------- .../wazuh_testing/tools/configuration.py | 4 +-- tests/integration/conftest.py | 4 +-- 3 files changed, 9 insertions(+), 34 deletions(-) diff --git a/deps/wazuh_testing/wazuh_testing/tools/__init__.py b/deps/wazuh_testing/wazuh_testing/tools/__init__.py index 811fb23fe2..b708365913 100644 --- a/deps/wazuh_testing/wazuh_testing/tools/__init__.py +++ b/deps/wazuh_testing/wazuh_testing/tools/__init__.py @@ -151,45 +151,22 @@ def get_service(): AUTHD_SOCKET_PATH ] -# Wazuh daemons -LOGCOLLECTOR_DAEMON = 'wazuh-logcollector' -AGENTLESS_DAEMON = 'wazuh-agentlessd' -CSYSLOG_DAEMON = 'wazuh-csyslogd' -REMOTE_DAEMON = 'wazuh-remoted' -ANALYSISD_DAEMON = 'wazuh-analysisd' -API_DAEMON = 'wazuh-apid' -MAIL_DAEMON = 'wazuh-maild' -SYSCHECK_DAEMON = 'wazuh-syscheckd' -EXEC_DAEMON = 'wazuh-execd' -MODULES_DAEMON = 'wazuh-modulesd' -CLUSTER_DAEMON = 'wazuh-clusterd' -INTEGRATOR_DAEMON = 'wazuh-integratord' -MONITOR_DAEMON = 'wazuh-monitord' -DB_DAEMON = 'wazuh-db' -AGENT_DAEMON = 'wazuh-agentd' - - -ALL_MANAGER_DAEMONS = [LOGCOLLECTOR_DAEMON, AGENTLESS_DAEMON, CSYSLOG_DAEMON, REMOTE_DAEMON, ANALYSISD_DAEMON, - API_DAEMON, MAIL_DAEMON, SYSCHECK_DAEMON, EXEC_DAEMON, MODULES_DAEMON, CLUSTER_DAEMON, - INTEGRATOR_DAEMON, MONITOR_DAEMON, DB_DAEMON] -ALL_AGENT_DAEMONS = [AGENT_DAEMON, EXEC_DAEMON, LOGCOLLECTOR_DAEMON, SYSCHECK_DAEMON, MODULES_DAEMON] -API_DAEMONS_REQUIREMENTS = [API_DAEMON, MODULES_DAEMON, ANALYSISD_DAEMON, EXEC_DAEMON, DB_DAEMON, REMOTE_DAEMON] - - DISABLE_MONITORD_ROTATE_LOG_OPTION = {'monitord.rotate_log': '0'} REMOTED_LOCAL_INTERNAL_OPTIONS = {'remoted.debug': '2'}.update(DISABLE_MONITORD_ROTATE_LOG_OPTION) ANALYSISD_LOCAL_INTERNAL_OPTIONS = {'analysisd.debug': '2'}.update(DISABLE_MONITORD_ROTATE_LOG_OPTION) AGENTD_LOCAL_INTERNAL_OPTIONS = {'agent.debug': '2', 'execd': '2'}.update(DISABLE_MONITORD_ROTATE_LOG_OPTION) + FIM_LOCAL_INTERNAL_OPTIONS_MANAGER = {'syscheck.debug': '2', - 'analysisd.debug': '2'}.update(DISABLE_MONITORD_ROTATE_LOG_OPTION) + 'analysisd.debug': '2'}.update(DISABLE_MONITORD_ROTATE_LOG_OPTION) FIM_LOCAL_INTERNAL_OPTIONS_AGENT_UNIX = {'syscheck.debug': '2', - 'agent.debug': '2'}.update(DISABLE_MONITORD_ROTATE_LOG_OPTION) + 'agent.debug': '2'}.update(DISABLE_MONITORD_ROTATE_LOG_OPTION) FIM_LOCAL_INTERNAL_OPTIONS_AGENT_WINDOWS = {'syscheck.debug': '2', 'windows.debug': '2'}.update(DISABLE_MONITORD_ROTATE_LOG_OPTION) + GCLOUD_LOCAL_INTERNAL_OPTIONS = {'analysisd.debug': '2', - 'wazuh_modules.debug': '2'}.update(DISABLE_MONITORD_ROTATE_LOG_OPTION) + 'wazuh_modules.debug': '2'}.update(DISABLE_MONITORD_ROTATE_LOG_OPTION) LOGTEST_LOCAL_INTERNAL_OPTIONS = {'analysisd.debug': '2'} REMOTED_LOCAL_INTERNAL_OPTIONS = {'remoted.debug': '2', 'wazuh_database.interval': '2', 'wazuh_db.commit_time': '2', - 'wazuh_db.commit_time_max': '3'}.update(DISABLE_MONITORD_ROTATE_LOG_OPTION) + 'wazuh_db.commit_time_max': '3' }.update(DISABLE_MONITORD_ROTATE_LOG_OPTION) VD_LOCAL_INTERNAL_OPTIONS = {'wazuh_modules.debug': '2'}.update(DISABLE_MONITORD_ROTATE_LOG_OPTION) WPK_LOCAL_INTERNAL_OPTIONS = {'wazuh_modules.debug': '2'} diff --git a/deps/wazuh_testing/wazuh_testing/tools/configuration.py b/deps/wazuh_testing/wazuh_testing/tools/configuration.py index bd06c1acb2..4fcc73c1df 100644 --- a/deps/wazuh_testing/wazuh_testing/tools/configuration.py +++ b/deps/wazuh_testing/wazuh_testing/tools/configuration.py @@ -603,7 +603,7 @@ def local_internal_options_to_dict(local_internal_options): def get_local_internal_options_dict(): - """Return the local internal options in a dictionary + """Return the local internal options in a dictionary. Returns: dict: Local internal options. @@ -620,7 +620,7 @@ def get_local_internal_options_dict(): def set_local_internal_options_dict(dict_local_internal_options): - """Set the local internal options using a dictionary + """Set the local internal options using a dictionary. Args: local_internal_options_dict (dict): A dictionary containing local internal options. diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index dbdcba25bb..bd72aa34a1 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -608,12 +608,11 @@ def configure_local_internal_options_module(request): local_internal_options = ['monitord.rotate_log': '0', 'syscheck.debug': '0' ] """ try: - local_internal_options = getattr(request.module, 'local_internal_options', []) + local_internal_options = getattr(request.module, 'local_internal_options') except AttributeError as local_internal_configuration_not_set: logger.error('Configure Local Internal Options: Error - local_internal_options is not set') raise local_internal_configuration_not_set - backup_local_internal_options = conf.get_local_internal_options_dict() logger.error('Configure Local Internal Options: DEBUG - Set local_internal_option to ' + @@ -622,7 +621,6 @@ def configure_local_internal_options_module(request): yield - logger.error('Configure Local Internal Options: DEBUG - Restore local_internal_option to ' + f"{str(backup_local_internal_options)}") conf.set_local_internal_options_dict(backup_local_internal_options) From 06d1bc3b7d9d2551d4e292f2938b1258747f2187 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Rebollo?= Date: Mon, 6 Sep 2021 17:45:11 +0200 Subject: [PATCH 03/27] Remove redundant logging messages --- tests/integration/conftest.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index bd72aa34a1..36785fe23f 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -610,17 +610,17 @@ def configure_local_internal_options_module(request): try: local_internal_options = getattr(request.module, 'local_internal_options') except AttributeError as local_internal_configuration_not_set: - logger.error('Configure Local Internal Options: Error - local_internal_options is not set') + logger.debug('local_internal_options is not set') raise local_internal_configuration_not_set backup_local_internal_options = conf.get_local_internal_options_dict() - logger.error('Configure Local Internal Options: DEBUG - Set local_internal_option to ' + - f"{str(local_internal_options)}") + logger.debug('Set local_internal_option to ' + + f"{str(local_internal_options)}") conf.set_local_internal_options_dict(local_internal_options) yield - logger.error('Configure Local Internal Options: DEBUG - Restore local_internal_option to ' + - f"{str(backup_local_internal_options)}") + logger.debug('Restore local_internal_option to ' + + f"{str(backup_local_internal_options)}") conf.set_local_internal_options_dict(backup_local_internal_options) From 790c2c33dba1798e0b4ae714cdc76929dbc5e5fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Rebollo?= Date: Mon, 6 Sep 2021 17:46:39 +0200 Subject: [PATCH 04/27] Refactor fixture --- tests/integration/conftest.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index 36785fe23f..593ddde270 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -615,12 +615,10 @@ def configure_local_internal_options_module(request): backup_local_internal_options = conf.get_local_internal_options_dict() - logger.debug('Set local_internal_option to ' + - f"{str(local_internal_options)}") + logger.debug(f"Set local_internal_option to {str(local_internal_options)}") conf.set_local_internal_options_dict(local_internal_options) yield - logger.debug('Restore local_internal_option to ' + - f"{str(backup_local_internal_options)}") + logger.debug(f"Restore local_internal_option to {str(backup_local_internal_options)}") conf.set_local_internal_options_dict(backup_local_internal_options) From b3d98b6d55b412db0bc84782f57aa35da29ef6f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Rebollo?= Date: Tue, 7 Sep 2021 09:11:00 +0200 Subject: [PATCH 05/27] Fix local internal option handler documentation --- tests/integration/conftest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index 593ddde270..9fadedd047 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -605,7 +605,7 @@ def configure_local_internal_options_module(request): It uses the test variable local_internal_options. This should be a dictionary wich keys and values corresponds to the internal option configuration, For example: - local_internal_options = ['monitord.rotate_log': '0', 'syscheck.debug': '0' ] + local_internal_options = {'monitord.rotate_log': '0', 'syscheck.debug': '0' } """ try: local_internal_options = getattr(request.module, 'local_internal_options') From 4d3835e5620856a9c5280f5ed9ba597a503ca21f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Rebollo?= Date: Wed, 1 Sep 2021 10:41:40 +0200 Subject: [PATCH 06/27] Create use_wazuh_daemons fixture for integration test --- tests/integration/conftest.py | 63 +++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index 9fadedd047..eaab5d97c2 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -622,3 +622,66 @@ def configure_local_internal_options_module(request): logger.debug(f"Restore local_internal_option to {str(backup_local_internal_options)}") conf.set_local_internal_options_dict(backup_local_internal_options) + + +@pytest.fixture(scope='module') +def use_wazuh_daemons(get_configuration, request): + """Wazuh daemons handler. + + It uses `wazuh_daemons_configuration` of each module in order to configure the behavior of the fixture. + In case this variable is not defined all wazuh modules will be restarted. + The `wazuh_daemons_configuration` should be a dictionary with the following keys: + + wazuh_daemons (list, optional): List with every daemon to be used by the module. In case of empty array, all Wazuh will be restarted. Default value empty. + truncate_log (boolean): Configure if ossec.log truncation. Default `True` + ignore_errors (boolean): Configure if errors in daemon handling should be ignore. Default `False` + + Args: + get_configuration (fixture): Gets the current configuration of the test. + request (fixture): Provide information on the executing test function. + """ + wazuh_daemons = [] + truncate_log = True + ignore_errors = False + + try: + wazuh_daemons_configuration = getattr(request.module, 'wazuh_daemons_configuration') + if 'wazuh_daemons' in wazuh_daemons_configuration: + wazuh_daemons = wazuh_daemons_configuration['wazuh_daemons'] + + if 'truncate_log' in wazuh_daemons_configuration: + truncate_log= wazuh_daemons_configuration['truncate_log'] + + if 'ignore_errors' in wazuh_daemons_configuration: + ignore_errors = wazuh_daemons_configuration['ignore_errors'] + + except AttributeError: + pass + + if truncate_log: + truncate_file(LOG_FILE_PATH) + + file_monitor = FileMonitor(LOG_FILE_PATH) + setattr(request.module, 'wazuh_log_monitor', file_monitor) + + + try: + if wazuh_daemons: + for daemon in wazuh_daemons: + control_service('restart', daemon=daemon) + else: + control_service('restart') + except ValueError as value_error: + if not ignore_errors: + raise value_error + except subprocess.CalledProcessError as called_process_error: + if not ignore_errors: + raise called_process_error + + yield + + if wazuh_daemons: + for daemon in wazuh_daemons: + control_service('stop', daemon=daemon) + else: + control_service('stop') From 306df6c703e2911bb29f721b503f540d11e24abd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Rebollo?= Date: Wed, 1 Sep 2021 13:05:00 +0200 Subject: [PATCH 07/27] Remove wazuh headers from daemon handler fixture --- tests/integration/conftest.py | 41 +++++++++++++++++------------------ 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index eaab5d97c2..108a59b691 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -625,14 +625,13 @@ def configure_local_internal_options_module(request): @pytest.fixture(scope='module') -def use_wazuh_daemons(get_configuration, request): - """Wazuh daemons handler. +def use_daemons(get_configuration, request): + """Daemons handler. - It uses `wazuh_daemons_configuration` of each module in order to configure the behavior of the fixture. - In case this variable is not defined all wazuh modules will be restarted. - The `wazuh_daemons_configuration` should be a dictionary with the following keys: - - wazuh_daemons (list, optional): List with every daemon to be used by the module. In case of empty array, all Wazuh will be restarted. Default value empty. + It uses `daemons_configuration` of each module in order to configure the behavior of the fixture. + The `daemons_configuration` should be a dictionary with the following keys: + daemons (list, optional): List with every daemon to be used by the module. In case of empty a ValueError + will be raised truncate_log (boolean): Configure if ossec.log truncation. Default `True` ignore_errors (boolean): Configure if errors in daemon handling should be ignore. Default `False` @@ -640,23 +639,23 @@ def use_wazuh_daemons(get_configuration, request): get_configuration (fixture): Gets the current configuration of the test. request (fixture): Provide information on the executing test function. """ - wazuh_daemons = [] + daemons = [] truncate_log = True ignore_errors = False try: - wazuh_daemons_configuration = getattr(request.module, 'wazuh_daemons_configuration') - if 'wazuh_daemons' in wazuh_daemons_configuration: - wazuh_daemons = wazuh_daemons_configuration['wazuh_daemons'] + daemons_configuration = getattr(request.module, 'daemons_configuration') + if 'daemons' in daemons_configuration: + daemons = daemons_configuration['daemons'] - if 'truncate_log' in wazuh_daemons_configuration: - truncate_log= wazuh_daemons_configuration['truncate_log'] + if 'truncate_log' in daemons_configuration: + truncate_log = daemons_configuration['truncate_log'] - if 'ignore_errors' in wazuh_daemons_configuration: - ignore_errors = wazuh_daemons_configuration['ignore_errors'] + if 'ignore_errors' in daemons_configuration: + ignore_errors = daemons_configuration['ignore_errors'] - except AttributeError: - pass + except AttributeError as daemon_configuration_not_set: + raise daemon_configuration_not_set if truncate_log: truncate_file(LOG_FILE_PATH) @@ -666,8 +665,8 @@ def use_wazuh_daemons(get_configuration, request): try: - if wazuh_daemons: - for daemon in wazuh_daemons: + if daemons: + for daemon in daemons: control_service('restart', daemon=daemon) else: control_service('restart') @@ -680,8 +679,8 @@ def use_wazuh_daemons(get_configuration, request): yield - if wazuh_daemons: - for daemon in wazuh_daemons: + if daemons: + for daemon in daemons: control_service('stop', daemon=daemon) else: control_service('stop') From f372278a758c73d65f7535dcb2e9e7f81dbbc77a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Rebollo?= Date: Thu, 2 Sep 2021 09:15:39 +0200 Subject: [PATCH 08/27] Remove filemonitor logic in use_daemons fixture Raise exception in case empty daemons list --- tests/integration/conftest.py | 32 +++++++++----------------------- 1 file changed, 9 insertions(+), 23 deletions(-) diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index 108a59b691..ee9f9060a3 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -632,24 +632,22 @@ def use_daemons(get_configuration, request): The `daemons_configuration` should be a dictionary with the following keys: daemons (list, optional): List with every daemon to be used by the module. In case of empty a ValueError will be raised - truncate_log (boolean): Configure if ossec.log truncation. Default `True` - ignore_errors (boolean): Configure if errors in daemon handling should be ignore. Default `False` + ignore_errors (boolean): Configure if errors in daemon handling should be ignore. This option is available + in order to use this fixture along with invalid configuration. Default `False` Args: get_configuration (fixture): Gets the current configuration of the test. request (fixture): Provide information on the executing test function. """ daemons = [] - truncate_log = True ignore_errors = False try: daemons_configuration = getattr(request.module, 'daemons_configuration') if 'daemons' in daemons_configuration: daemons = daemons_configuration['daemons'] - - if 'truncate_log' in daemons_configuration: - truncate_log = daemons_configuration['truncate_log'] + if not daemons: + raise ValueError if 'ignore_errors' in daemons_configuration: ignore_errors = daemons_configuration['ignore_errors'] @@ -657,19 +655,10 @@ def use_daemons(get_configuration, request): except AttributeError as daemon_configuration_not_set: raise daemon_configuration_not_set - if truncate_log: - truncate_file(LOG_FILE_PATH) - - file_monitor = FileMonitor(LOG_FILE_PATH) - setattr(request.module, 'wazuh_log_monitor', file_monitor) - - try: - if daemons: - for daemon in daemons: - control_service('restart', daemon=daemon) - else: - control_service('restart') + for daemon in daemons: + control_service('restart', daemon=daemon) + except ValueError as value_error: if not ignore_errors: raise value_error @@ -679,8 +668,5 @@ def use_daemons(get_configuration, request): yield - if daemons: - for daemon in daemons: - control_service('stop', daemon=daemon) - else: - control_service('stop') + for daemon in daemons: + control_service('stop', daemon=daemon) From 5d45240c8fe36bc9987afcecd3f4d35735ae96b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Rebollo?= Date: Thu, 2 Sep 2021 09:17:14 +0200 Subject: [PATCH 09/27] Rename use_daemons fixture to daemons_handler --- tests/integration/conftest.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index ee9f9060a3..66ea949db0 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -625,8 +625,8 @@ def configure_local_internal_options_module(request): @pytest.fixture(scope='module') -def use_daemons(get_configuration, request): - """Daemons handler. +def daemons_handler(get_configuration, request): + """Handler of Wazuh daemons. It uses `daemons_configuration` of each module in order to configure the behavior of the fixture. The `daemons_configuration` should be a dictionary with the following keys: From 666d763d34fe5103c201aab98dd6f2cb31d3675e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Rebollo?= Date: Thu, 2 Sep 2021 09:47:20 +0200 Subject: [PATCH 10/27] Renmae daemons_configuration as daemons_handler_configuration --- tests/integration/conftest.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index 66ea949db0..f257868431 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -643,30 +643,37 @@ def daemons_handler(get_configuration, request): ignore_errors = False try: - daemons_configuration = getattr(request.module, 'daemons_configuration') - if 'daemons' in daemons_configuration: - daemons = daemons_configuration['daemons'] + daemons_handler_configuration = getattr(request.module, 'daemons_handler_configuration') + if 'daemons' in daemons_handler_configuration: + daemons = daemons_handler_configuration['daemons'] if not daemons: + logger.error('Daemons Handler: Daemons list is not set') raise ValueError - if 'ignore_errors' in daemons_configuration: - ignore_errors = daemons_configuration['ignore_errors'] + if 'ignore_errors' in daemons_handler_configuration: + logger.debug(f"Daemons Handler: Ignore error set to {daemons_handler_configuration['ignore_errors']}") + ignore_errors = daemons_handler_configuration['ignore_errors'] except AttributeError as daemon_configuration_not_set: - raise daemon_configuration_not_set + logger.error('Daemons Handler: Error - daemons_handler_configuration is not set') + raise daemon_configuration_not_set try: for daemon in daemons: + logger.debug(f"Daemons Handler: Restarting {daemon}") control_service('restart', daemon=daemon) except ValueError as value_error: + logger.error(f"Daemons Handler: Error - {str(value_error)}") if not ignore_errors: raise value_error except subprocess.CalledProcessError as called_process_error: + logger.error(f"Daemons Handler: Error - {str(called_process_error)}") if not ignore_errors: raise called_process_error yield for daemon in daemons: + logger.debug(f"Daemons Handler: Stopping {daemon}") control_service('stop', daemon=daemon) From 8624a8fe81e2b8227992f6a7ab0837a0a925a6fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Rebollo?= Date: Thu, 2 Sep 2021 09:49:49 +0200 Subject: [PATCH 11/27] Rename damons_configuration as daemons_handler_configuration in fixture documentation --- tests/integration/conftest.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index f257868431..28dd093b89 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -628,8 +628,8 @@ def configure_local_internal_options_module(request): def daemons_handler(get_configuration, request): """Handler of Wazuh daemons. - It uses `daemons_configuration` of each module in order to configure the behavior of the fixture. - The `daemons_configuration` should be a dictionary with the following keys: + It uses `daemons_handler_configuration` of each module in order to configure the behavior of the fixture. + The `daemons_handler_configuration` should be a dictionary with the following keys: daemons (list, optional): List with every daemon to be used by the module. In case of empty a ValueError will be raised ignore_errors (boolean): Configure if errors in daemon handling should be ignore. This option is available From 807076f01df4503315b42eff9017d1b4725a7127 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Rebollo?= Date: Thu, 2 Sep 2021 12:36:03 +0200 Subject: [PATCH 12/27] Add wazuh daemons to the tools library Create option for daemon_handler to use wazuh_control --- .../wazuh_testing/tools/__init__.py | 25 +++++++++++++++ tests/integration/conftest.py | 31 ++++++++++++++----- 2 files changed, 49 insertions(+), 7 deletions(-) diff --git a/deps/wazuh_testing/wazuh_testing/tools/__init__.py b/deps/wazuh_testing/wazuh_testing/tools/__init__.py index b708365913..0e69b9140a 100644 --- a/deps/wazuh_testing/wazuh_testing/tools/__init__.py +++ b/deps/wazuh_testing/wazuh_testing/tools/__init__.py @@ -170,3 +170,28 @@ def get_service(): 'wazuh_db.commit_time_max': '3' }.update(DISABLE_MONITORD_ROTATE_LOG_OPTION) VD_LOCAL_INTERNAL_OPTIONS = {'wazuh_modules.debug': '2'}.update(DISABLE_MONITORD_ROTATE_LOG_OPTION) WPK_LOCAL_INTERNAL_OPTIONS = {'wazuh_modules.debug': '2'} + + +# Wazuh daemons +LOGCOLLECTOR_DAEMON = 'wazuh-logcollector' +AGENTLESS_DAEMON = 'wazuh-agentlessd' +CSYSLOG_DAEMON = 'wazuh-csyslogd' +REMOTE_DAEMON = 'wazuh-remoted' +ANALYSISD_DAEMON = 'wazuh-analysisd' +API_DAEMON = 'wazuh-apid' +MAIL_DAEMON = 'wazuh-maild' +SYSCHECK_DAEMON = 'wazuh-syscheckd' +EXEC_DAEMON = 'wazuh-execd' +MODULES_DAEMON = 'wazuh-modulesd' +CLUSTER_DAEMON = 'wazuh-clusterd' +INTEGRATOR_DAEMON = 'wazuh-integratord' +MONITOR_DAEMON = 'wazuh-monitord' +DB_DAEMON = 'wazuh-db' +AGENT_DAEMON = 'wazuh-agentd' + + +ALL_MANAGER_DAEMONS = [LOGCOLLECTOR_DAEMON, AGENTLESS_DAEMON, CSYSLOG_DAEMON, REMOTE_DAEMON, ANALYSISD_DAEMON, + API_DAEMON, MAIL_DAEMON, SYSCHECK_DAEMON, EXEC_DAEMON, MODULES_DAEMON, CLUSTER_DAEMON, INTEGRATOR_DAEMON, MONITOR_DAEMON, + DB_DAEMON ] +ALL_AGENT_DAEMONS = [AGENT_DAEMON, EXEC_DAEMON, LOGCOLLECTOR_DAEMON, SYSCHECK_DAEMON, MODULES_DAEMON] +API_DAEMON_REQUIREMENTS = [API_DAEMON, MODULES_DAEMON, ANALYSISD_DAEMON, EXEC_DAEMON, DB_DAEMON, REMOTE_DAEMON] diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index 28dd093b89..f26c31e9ad 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -632,6 +632,7 @@ def daemons_handler(get_configuration, request): The `daemons_handler_configuration` should be a dictionary with the following keys: daemons (list, optional): List with every daemon to be used by the module. In case of empty a ValueError will be raised + wazuh_control (boolean): Configure to restart all wazuh services. Default `False`. ignore_errors (boolean): Configure if errors in daemon handling should be ignore. This option is available in order to use this fixture along with invalid configuration. Default `False` @@ -641,15 +642,20 @@ def daemons_handler(get_configuration, request): """ daemons = [] ignore_errors = False + wazuh_control = False try: daemons_handler_configuration = getattr(request.module, 'daemons_handler_configuration') - if 'daemons' in daemons_handler_configuration: + if 'daemons' in daemons_handler_configuration and not wazuh_control: daemons = daemons_handler_configuration['daemons'] if not daemons: logger.error('Daemons Handler: Daemons list is not set') raise ValueError + if 'wazuh_control' in daemons_handler_configuration: + logger.debug(f"Daemons Handler: Wazuh control set to {daemons_handler_configuration['wazuh_control']}") + wazuh_control = daemons_handler_configuration['wazuh_control'] + if 'ignore_errors' in daemons_handler_configuration: logger.debug(f"Daemons Handler: Ignore error set to {daemons_handler_configuration['ignore_errors']}") ignore_errors = daemons_handler_configuration['ignore_errors'] @@ -658,10 +664,17 @@ def daemons_handler(get_configuration, request): logger.error('Daemons Handler: Error - daemons_handler_configuration is not set') raise daemon_configuration_not_set + try: - for daemon in daemons: - logger.debug(f"Daemons Handler: Restarting {daemon}") - control_service('restart', daemon=daemon) + if wazuh_control: + logger.debug('Daemons Handler: Debug - Restarting wazuh using wazuh-control') + # Restart daemon instead of starting due to legacy used fixture in the test suite. + control_service('restart') + else: + for daemon in daemons: + logger.debug(f"Daemons Handler: Restarting {daemon}") + # Restart daemon instead of starting due to legacy used fixture in the test suite. + control_service('restart', daemon=daemon) except ValueError as value_error: logger.error(f"Daemons Handler: Error - {str(value_error)}") @@ -674,6 +687,10 @@ def daemons_handler(get_configuration, request): yield - for daemon in daemons: - logger.debug(f"Daemons Handler: Stopping {daemon}") - control_service('stop', daemon=daemon) + if wazuh_control: + logger.debug('Daemons Handler: Debug - Stopping wazuh using wazuh-control') + control_service('stop') + else: + for daemon in daemons: + logger.debug(f"Daemons Handler: Stopping {daemon}") + control_service('stop', daemon=daemon) From d6df182ad8eaf344bc542a4579a4ab6e03558682 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Rebollo?= Date: Thu, 2 Sep 2021 12:41:39 +0200 Subject: [PATCH 13/27] Remove tailing whitespace and useless blank lines --- tests/integration/conftest.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index f26c31e9ad..702d24c621 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -628,7 +628,7 @@ def configure_local_internal_options_module(request): def daemons_handler(get_configuration, request): """Handler of Wazuh daemons. - It uses `daemons_handler_configuration` of each module in order to configure the behavior of the fixture. + It uses `daemons_handler_configuration` of each module in order to configure the behavior of the fixture. The `daemons_handler_configuration` should be a dictionary with the following keys: daemons (list, optional): List with every daemon to be used by the module. In case of empty a ValueError will be raised @@ -664,7 +664,6 @@ def daemons_handler(get_configuration, request): logger.error('Daemons Handler: Error - daemons_handler_configuration is not set') raise daemon_configuration_not_set - try: if wazuh_control: logger.debug('Daemons Handler: Debug - Restarting wazuh using wazuh-control') From 9f9ade9c1948afee7bd48eae1aeff9f51f7a72a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Rebollo?= Date: Thu, 2 Sep 2021 13:56:41 +0200 Subject: [PATCH 14/27] Apply minnor changes in variable names and daemon_handler fixture Rename api daemons Fix minnor docstring error in daemon_handler fixture Improve daemons list valid value Co-authored-by: Jonathan --- deps/wazuh_testing/wazuh_testing/tools/__init__.py | 2 +- tests/integration/conftest.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/deps/wazuh_testing/wazuh_testing/tools/__init__.py b/deps/wazuh_testing/wazuh_testing/tools/__init__.py index 0e69b9140a..556569d453 100644 --- a/deps/wazuh_testing/wazuh_testing/tools/__init__.py +++ b/deps/wazuh_testing/wazuh_testing/tools/__init__.py @@ -194,4 +194,4 @@ def get_service(): API_DAEMON, MAIL_DAEMON, SYSCHECK_DAEMON, EXEC_DAEMON, MODULES_DAEMON, CLUSTER_DAEMON, INTEGRATOR_DAEMON, MONITOR_DAEMON, DB_DAEMON ] ALL_AGENT_DAEMONS = [AGENT_DAEMON, EXEC_DAEMON, LOGCOLLECTOR_DAEMON, SYSCHECK_DAEMON, MODULES_DAEMON] -API_DAEMON_REQUIREMENTS = [API_DAEMON, MODULES_DAEMON, ANALYSISD_DAEMON, EXEC_DAEMON, DB_DAEMON, REMOTE_DAEMON] +API_DAEMONS_REQUIREMENTS = [API_DAEMON, MODULES_DAEMON, ANALYSISD_DAEMON, EXEC_DAEMON, DB_DAEMON, REMOTE_DAEMON] diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index 702d24c621..62a1ad12fa 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -633,7 +633,7 @@ def daemons_handler(get_configuration, request): daemons (list, optional): List with every daemon to be used by the module. In case of empty a ValueError will be raised wazuh_control (boolean): Configure to restart all wazuh services. Default `False`. - ignore_errors (boolean): Configure if errors in daemon handling should be ignore. This option is available + ignore_errors (boolean): Configure if errors in daemon handling should be ignored. This option is available in order to use this fixture along with invalid configuration. Default `False` Args: @@ -648,7 +648,7 @@ def daemons_handler(get_configuration, request): daemons_handler_configuration = getattr(request.module, 'daemons_handler_configuration') if 'daemons' in daemons_handler_configuration and not wazuh_control: daemons = daemons_handler_configuration['daemons'] - if not daemons: + if not daemons or (type(daemons) == list and len(daemons) == 0): logger.error('Daemons Handler: Daemons list is not set') raise ValueError From 42f516f5fb8545ab222b9f1c1688ad3ef5bcea62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Rebollo?= Date: Mon, 6 Sep 2021 17:20:29 +0200 Subject: [PATCH 15/27] Minnor style fix for fulfull pep8 --- deps/wazuh_testing/wazuh_testing/tools/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/deps/wazuh_testing/wazuh_testing/tools/__init__.py b/deps/wazuh_testing/wazuh_testing/tools/__init__.py index 556569d453..a5ae541fa6 100644 --- a/deps/wazuh_testing/wazuh_testing/tools/__init__.py +++ b/deps/wazuh_testing/wazuh_testing/tools/__init__.py @@ -191,7 +191,7 @@ def get_service(): ALL_MANAGER_DAEMONS = [LOGCOLLECTOR_DAEMON, AGENTLESS_DAEMON, CSYSLOG_DAEMON, REMOTE_DAEMON, ANALYSISD_DAEMON, - API_DAEMON, MAIL_DAEMON, SYSCHECK_DAEMON, EXEC_DAEMON, MODULES_DAEMON, CLUSTER_DAEMON, INTEGRATOR_DAEMON, MONITOR_DAEMON, - DB_DAEMON ] + API_DAEMON, MAIL_DAEMON, SYSCHECK_DAEMON, EXEC_DAEMON, MODULES_DAEMON, CLUSTER_DAEMON, + INTEGRATOR_DAEMON, MONITOR_DAEMON, DB_DAEMON] ALL_AGENT_DAEMONS = [AGENT_DAEMON, EXEC_DAEMON, LOGCOLLECTOR_DAEMON, SYSCHECK_DAEMON, MODULES_DAEMON] API_DAEMONS_REQUIREMENTS = [API_DAEMON, MODULES_DAEMON, ANALYSISD_DAEMON, EXEC_DAEMON, DB_DAEMON, REMOTE_DAEMON] From 321e7d86c5b1ec6684e5977dbba36de6b7a8a63a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Rebollo?= Date: Mon, 6 Sep 2021 17:55:04 +0200 Subject: [PATCH 16/27] Remove redundant logging messages --- tests/integration/conftest.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index 62a1ad12fa..7ed0528a7b 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -649,47 +649,47 @@ def daemons_handler(get_configuration, request): if 'daemons' in daemons_handler_configuration and not wazuh_control: daemons = daemons_handler_configuration['daemons'] if not daemons or (type(daemons) == list and len(daemons) == 0): - logger.error('Daemons Handler: Daemons list is not set') + logger.error('Daemons list is not set') raise ValueError if 'wazuh_control' in daemons_handler_configuration: - logger.debug(f"Daemons Handler: Wazuh control set to {daemons_handler_configuration['wazuh_control']}") + logger.debug(f"Wazuh control set to {daemons_handler_configuration['wazuh_control']}") wazuh_control = daemons_handler_configuration['wazuh_control'] if 'ignore_errors' in daemons_handler_configuration: - logger.debug(f"Daemons Handler: Ignore error set to {daemons_handler_configuration['ignore_errors']}") + logger.debug(f"Ignore error set to {daemons_handler_configuration['ignore_errors']}") ignore_errors = daemons_handler_configuration['ignore_errors'] except AttributeError as daemon_configuration_not_set: - logger.error('Daemons Handler: Error - daemons_handler_configuration is not set') + logger.error('daemons_handler_configuration is not set') raise daemon_configuration_not_set try: if wazuh_control: - logger.debug('Daemons Handler: Debug - Restarting wazuh using wazuh-control') + logger.debug('Restarting wazuh using wazuh-control') # Restart daemon instead of starting due to legacy used fixture in the test suite. control_service('restart') else: for daemon in daemons: - logger.debug(f"Daemons Handler: Restarting {daemon}") + logger.debug(f"Restarting {daemon}") # Restart daemon instead of starting due to legacy used fixture in the test suite. control_service('restart', daemon=daemon) except ValueError as value_error: - logger.error(f"Daemons Handler: Error - {str(value_error)}") + logger.error(f"{str(value_error)}") if not ignore_errors: raise value_error except subprocess.CalledProcessError as called_process_error: - logger.error(f"Daemons Handler: Error - {str(called_process_error)}") + logger.error(f"{str(called_process_error)}") if not ignore_errors: raise called_process_error yield if wazuh_control: - logger.debug('Daemons Handler: Debug - Stopping wazuh using wazuh-control') + logger.debug('Stopping wazuh using wazuh-control') control_service('stop') else: for daemon in daemons: - logger.debug(f"Daemons Handler: Stopping {daemon}") + logger.debug(f"Stopping {daemon}") control_service('stop', daemon=daemon) From da78be512fd841561c81abd26d3671a6b3d31258 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Rebollo?= Date: Tue, 7 Sep 2021 09:58:54 +0200 Subject: [PATCH 17/27] Rename wazuh_control by restart_all --- tests/integration/conftest.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index 7ed0528a7b..294c321d24 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -632,7 +632,7 @@ def daemons_handler(get_configuration, request): The `daemons_handler_configuration` should be a dictionary with the following keys: daemons (list, optional): List with every daemon to be used by the module. In case of empty a ValueError will be raised - wazuh_control (boolean): Configure to restart all wazuh services. Default `False`. + restart_all (boolean): Configure to restart all wazuh services. Default `False`. ignore_errors (boolean): Configure if errors in daemon handling should be ignored. This option is available in order to use this fixture along with invalid configuration. Default `False` @@ -642,19 +642,19 @@ def daemons_handler(get_configuration, request): """ daemons = [] ignore_errors = False - wazuh_control = False + restart_all = False try: daemons_handler_configuration = getattr(request.module, 'daemons_handler_configuration') - if 'daemons' in daemons_handler_configuration and not wazuh_control: + if 'daemons' in daemons_handler_configuration and not restart_all: daemons = daemons_handler_configuration['daemons'] if not daemons or (type(daemons) == list and len(daemons) == 0): logger.error('Daemons list is not set') raise ValueError - if 'wazuh_control' in daemons_handler_configuration: - logger.debug(f"Wazuh control set to {daemons_handler_configuration['wazuh_control']}") - wazuh_control = daemons_handler_configuration['wazuh_control'] + if 'restart_all' in daemons_handler_configuration: + logger.debug(f"Wazuh control set to {daemons_handler_configuration['restart_all']}") + restart_all = daemons_handler_configuration['restart_all'] if 'ignore_errors' in daemons_handler_configuration: logger.debug(f"Ignore error set to {daemons_handler_configuration['ignore_errors']}") @@ -665,7 +665,7 @@ def daemons_handler(get_configuration, request): raise daemon_configuration_not_set try: - if wazuh_control: + if restart_all: logger.debug('Restarting wazuh using wazuh-control') # Restart daemon instead of starting due to legacy used fixture in the test suite. control_service('restart') @@ -686,7 +686,7 @@ def daemons_handler(get_configuration, request): yield - if wazuh_control: + if restart_all: logger.debug('Stopping wazuh using wazuh-control') control_service('stop') else: From 1e59fdc71838097328febc7795f3514a6aebebb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Rebollo?= Date: Tue, 7 Sep 2021 10:03:17 +0200 Subject: [PATCH 18/27] Rename restart_all by all_daemons --- tests/integration/conftest.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index 294c321d24..21f55068b7 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -632,7 +632,7 @@ def daemons_handler(get_configuration, request): The `daemons_handler_configuration` should be a dictionary with the following keys: daemons (list, optional): List with every daemon to be used by the module. In case of empty a ValueError will be raised - restart_all (boolean): Configure to restart all wazuh services. Default `False`. + all_daemons (boolean): Configure to restart all wazuh services. Default `False`. ignore_errors (boolean): Configure if errors in daemon handling should be ignored. This option is available in order to use this fixture along with invalid configuration. Default `False` @@ -642,19 +642,19 @@ def daemons_handler(get_configuration, request): """ daemons = [] ignore_errors = False - restart_all = False + all_daemons = False try: daemons_handler_configuration = getattr(request.module, 'daemons_handler_configuration') - if 'daemons' in daemons_handler_configuration and not restart_all: + if 'daemons' in daemons_handler_configuration and not all_daemons: daemons = daemons_handler_configuration['daemons'] if not daemons or (type(daemons) == list and len(daemons) == 0): logger.error('Daemons list is not set') raise ValueError - if 'restart_all' in daemons_handler_configuration: - logger.debug(f"Wazuh control set to {daemons_handler_configuration['restart_all']}") - restart_all = daemons_handler_configuration['restart_all'] + if 'all_daemons' in daemons_handler_configuration: + logger.debug(f"Wazuh control set to {daemons_handler_configuration['all_daemons']}") + all_daemons = daemons_handler_configuration['all_daemons'] if 'ignore_errors' in daemons_handler_configuration: logger.debug(f"Ignore error set to {daemons_handler_configuration['ignore_errors']}") @@ -665,7 +665,7 @@ def daemons_handler(get_configuration, request): raise daemon_configuration_not_set try: - if restart_all: + if all_daemons: logger.debug('Restarting wazuh using wazuh-control') # Restart daemon instead of starting due to legacy used fixture in the test suite. control_service('restart') @@ -686,7 +686,7 @@ def daemons_handler(get_configuration, request): yield - if restart_all: + if all_daemons: logger.debug('Stopping wazuh using wazuh-control') control_service('stop') else: From eeeab01cc240577fe22c497b9d5e2772106f8b9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Rebollo?= Date: Thu, 2 Sep 2021 13:09:21 +0200 Subject: [PATCH 19/27] Create file_monitoring fixture --- tests/integration/conftest.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index 21f55068b7..af77a2a949 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -693,3 +693,28 @@ def daemons_handler(get_configuration, request): for daemon in daemons: logger.debug(f"Stopping {daemon}") control_service('stop', daemon=daemon) + + +@pytest.fixture(scope='function') +def file_monitoring(request): + """Fixture to handle the monitoring of a specified file. + + It uses de variable `file_to_monitor` to determinate the file to monitor. Default `LOG_FILE_PATH` + + Args: + request (fixture): Provide information on the executing test function. + """ + if hasattr(request.module, 'file_to_monitor'): + file_to_monitor = getattr(request.module, 'file_to_monitor') + else: + file_to_monitor = LOG_FILE_PATH + + logger.debug(f"File monitoring - DEBUG - Initializing file to monitor to {file_to_monitor}") + + file_monitor = FileMonitor(file_to_monitor) + setattr(request.module, 'log_monitor', file_monitor) + + yield + + truncate_file(file_to_monitor) + logger.debug(f"File monitoring - DEBUG - Trucanted {file_to_monitor}") From 6114e5d4a00c9b4933b8dd395621942187ed0aeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Rebollo?= Date: Thu, 2 Sep 2021 13:17:12 +0200 Subject: [PATCH 20/27] Remove white spaces from blank lines --- tests/integration/conftest.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index af77a2a949..64a530dc7b 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -698,7 +698,7 @@ def daemons_handler(get_configuration, request): @pytest.fixture(scope='function') def file_monitoring(request): """Fixture to handle the monitoring of a specified file. - + It uses de variable `file_to_monitor` to determinate the file to monitor. Default `LOG_FILE_PATH` Args: @@ -708,12 +708,12 @@ def file_monitoring(request): file_to_monitor = getattr(request.module, 'file_to_monitor') else: file_to_monitor = LOG_FILE_PATH - + logger.debug(f"File monitoring - DEBUG - Initializing file to monitor to {file_to_monitor}") file_monitor = FileMonitor(file_to_monitor) setattr(request.module, 'log_monitor', file_monitor) - + yield truncate_file(file_to_monitor) From 7ab976a69e535fe754b643feeaf81a190cc29aac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Rebollo?= Date: Mon, 6 Sep 2021 17:52:30 +0200 Subject: [PATCH 21/27] Remove redundant logging messages --- tests/integration/conftest.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index 64a530dc7b..f97159dd6a 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -709,7 +709,7 @@ def file_monitoring(request): else: file_to_monitor = LOG_FILE_PATH - logger.debug(f"File monitoring - DEBUG - Initializing file to monitor to {file_to_monitor}") + logger.debug(f"Initializing file to monitor to {file_to_monitor}") file_monitor = FileMonitor(file_to_monitor) setattr(request.module, 'log_monitor', file_monitor) @@ -717,4 +717,4 @@ def file_monitoring(request): yield truncate_file(file_to_monitor) - logger.debug(f"File monitoring - DEBUG - Trucanted {file_to_monitor}") + logger.debug(f"Trucanted {file_to_monitor}") From 90bd4a5e7f52a65a5a41d3566095f1189a00ed6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Rebollo?= Date: Tue, 7 Sep 2021 11:52:01 +0200 Subject: [PATCH 22/27] Fix cherry-pick from master to 4.2 errors --- deps/wazuh_testing/wazuh_testing/tools/__init__.py | 6 +++--- tests/integration/conftest.py | 3 +-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/deps/wazuh_testing/wazuh_testing/tools/__init__.py b/deps/wazuh_testing/wazuh_testing/tools/__init__.py index a5ae541fa6..e0372cacdb 100644 --- a/deps/wazuh_testing/wazuh_testing/tools/__init__.py +++ b/deps/wazuh_testing/wazuh_testing/tools/__init__.py @@ -53,8 +53,8 @@ import grp import pwd - WAZUH_UID = pwd.getpwnam("wazuh").pw_uid - WAZUH_GID = grp.getgrnam("wazuh").gr_gid + WAZUH_UID = pwd.getpwnam("ossec").pw_uid + WAZUH_GID = grp.getgrnam("ossec").gr_gid except (ImportError, KeyError, ModuleNotFoundError): pass @@ -84,7 +84,7 @@ def get_service(): return 'wazuh-manager' if service == 'server' else 'wazuh-agent' -_data_path = os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))), 'data') +_data_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'data') CLIENT_KEYS_PATH = os.path.join(WAZUH_PATH, 'etc', 'client.keys') SERVER_KEY_PATH = os.path.join(WAZUH_PATH, 'etc', 'manager.key') diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index f97159dd6a..497567c74a 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -17,7 +17,6 @@ import wazuh_testing.tools.configuration as conf from wazuh_testing import global_parameters, logger -from wazuh_testing.logcollector import create_file_structure, delete_file_structure from wazuh_testing.tools import LOG_FILE_PATH, WAZUH_CONF, get_service, ALERT_FILE_PATH from wazuh_testing.tools.configuration import get_wazuh_conf, set_section_wazuh_conf, write_wazuh_conf from wazuh_testing.tools.file import truncate_file @@ -599,7 +598,7 @@ def create_file_structure_function(get_files_list): delete_file_structure(get_files_list) -@pytest.fixture(scope="module") +@pytest.fixture(scope='module') def configure_local_internal_options_module(request): """Fixture to configure the local internal options file. From 774cdb12c9ffcba252a0a91e2c8274dd6937433e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Rebollo?= Date: Tue, 7 Sep 2021 12:46:31 +0200 Subject: [PATCH 23/27] Fix error in tools package --- deps/wazuh_testing/wazuh_testing/tools/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/deps/wazuh_testing/wazuh_testing/tools/__init__.py b/deps/wazuh_testing/wazuh_testing/tools/__init__.py index e0372cacdb..d883d2517d 100644 --- a/deps/wazuh_testing/wazuh_testing/tools/__init__.py +++ b/deps/wazuh_testing/wazuh_testing/tools/__init__.py @@ -53,8 +53,8 @@ import grp import pwd - WAZUH_UID = pwd.getpwnam("ossec").pw_uid - WAZUH_GID = grp.getgrnam("ossec").gr_gid + OSSEC_UID = pwd.getpwnam("ossec").pw_uid + OSSEC_GID = grp.getgrnam("ossec").gr_gid except (ImportError, KeyError, ModuleNotFoundError): pass From 3b770c6bb19e16904301e237171eafa7323fe6b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Rebollo?= Date: Tue, 7 Sep 2021 12:49:09 +0200 Subject: [PATCH 24/27] Add upgrade path to tools package --- deps/wazuh_testing/wazuh_testing/tools/__init__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/deps/wazuh_testing/wazuh_testing/tools/__init__.py b/deps/wazuh_testing/wazuh_testing/tools/__init__.py index d883d2517d..10aae3911a 100644 --- a/deps/wazuh_testing/wazuh_testing/tools/__init__.py +++ b/deps/wazuh_testing/wazuh_testing/tools/__init__.py @@ -3,9 +3,9 @@ # This program is free software; you can redistribute it and/or modify it under the terms of GPLv2 import os +import sys import platform import subprocess -import sys if sys.platform == 'win32': WAZUH_PATH = os.path.join("C:", os.sep, "Program Files (x86)", "ossec-agent") @@ -22,6 +22,7 @@ LOGCOLLECTOR_STATISTICS_FILE = os.path.join(WAZUH_PATH, 'wazuh-logcollector.state') REMOTE_STATISTICS_FILE = None ANALYSIS_STATISTICS_FILE = None + UPGRADE_PATH = os.path.join(WAZUH_PATH, 'upgrade') else: @@ -48,6 +49,7 @@ LOGCOLLECTOR_STATISTICS_FILE = os.path.join(WAZUH_PATH, 'var', 'run', 'wazuh-logcollector.state') REMOTE_STATISTICS_FILE = os.path.join(WAZUH_PATH, 'var', 'run', 'wazuh-remoted.state') ANALYSIS_STATISTICS_FILE = os.path.join(WAZUH_PATH, 'var', 'run', 'wazuh-analysisd.state') + UPGRADE_PATH = os.path.join(WAZUH_PATH, 'var', 'upgrade') try: import grp From 0d794872f97f8617a9f385637a5c6472cb33a098 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Rebollo?= Date: Tue, 7 Sep 2021 13:38:17 +0200 Subject: [PATCH 25/27] Removed keys and cert path from tools package --- deps/wazuh_testing/wazuh_testing/tools/__init__.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/deps/wazuh_testing/wazuh_testing/tools/__init__.py b/deps/wazuh_testing/wazuh_testing/tools/__init__.py index 10aae3911a..571a583c4d 100644 --- a/deps/wazuh_testing/wazuh_testing/tools/__init__.py +++ b/deps/wazuh_testing/wazuh_testing/tools/__init__.py @@ -88,17 +88,9 @@ def get_service(): _data_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'data') -CLIENT_KEYS_PATH = os.path.join(WAZUH_PATH, 'etc', 'client.keys') -SERVER_KEY_PATH = os.path.join(WAZUH_PATH, 'etc', 'manager.key') -SERVER_CERT_PATH = os.path.join(WAZUH_PATH, 'etc', 'manager.cert') - -CLIENT_CUSTOM_KEYS_PATH = os.path.join(_data_path, 'sslmanager.key') -CLIENT_CUSTOM_CERT_PATH = os.path.join(_data_path, 'sslmanager.cert') - WAZUH_LOGS_PATH = os.path.join(WAZUH_PATH, 'logs') ALERT_FILE_PATH = os.path.join(WAZUH_LOGS_PATH, 'alerts', 'alerts.json') CLUSTER_LOGS_PATH = os.path.join(WAZUH_LOGS_PATH, 'cluster.log') - QUEUE_SOCKETS_PATH = os.path.join(WAZUH_PATH, 'queue', 'sockets') QUEUE_ALERTS_PATH = os.path.join(WAZUH_PATH, 'queue', 'alerts') QUEUE_DB_PATH = os.path.join(WAZUH_PATH, 'queue', 'db') From ac537a18e47c9e8414a67a7d83b3e8cee05b3e41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Rebollo?= Date: Tue, 7 Sep 2021 15:38:08 +0200 Subject: [PATCH 26/27] Remove unnused configuration fucntions --- .../wazuh_testing/tools/configuration.py | 60 ------------------- 1 file changed, 60 deletions(-) diff --git a/deps/wazuh_testing/wazuh_testing/tools/configuration.py b/deps/wazuh_testing/wazuh_testing/tools/configuration.py index 4fcc73c1df..4d4dab90da 100644 --- a/deps/wazuh_testing/wazuh_testing/tools/configuration.py +++ b/deps/wazuh_testing/wazuh_testing/tools/configuration.py @@ -542,66 +542,6 @@ def generate_syscheck_registry_config(): yield ' '.join([yn_str, tag_value]) -def get_wazuh_local_internal_options() -> List[str]: - """Get current `internal_options.conf` file content. - - Returns - List of str: A list containing all the lines of the `ossec.conf` file. - """ - with open(WAZUH_LOCAL_INTERNAL_OPTIONS) as f: - lines = f.readlines() - return lines - - -def set_wazuh_local_internal_options(wazuh_local_internal_options: List[str]): - """Set up Wazuh `local_internal_options.conf` file content. - - Returns - List of str: A list containing all the lines of the `local_interal_options.conf` file. - """ - with open(WAZUH_LOCAL_INTERNAL_OPTIONS, 'w') as f: - f.writelines(wazuh_local_internal_options) - - -def add_wazuh_local_internal_options(wazuh_local_internal_options_dict): - """Add new local internal options to the current configuration. - - Args: - wazuh_local_internal_options_dict (List of str): A list containing local internal options to add. - """ - local_internal_options_str = create_local_internal_options(wazuh_local_internal_options_dict) - with open(WAZUH_LOCAL_INTERNAL_OPTIONS, 'a') as f: - f.writelines(local_internal_options_str) - - -def create_local_internal_options(dict_local_internal_options): - """Create local_internal_options using a dictionary. - - Args: - dict_local_internal_options (dict) : Dictionary with the local internal options - """ - wazuh_local_internal_options = '' - for key, value in dict_local_internal_options.items(): - wazuh_local_internal_options += f"{str(key)}={str(value)}\n" - return wazuh_local_internal_options - - -def local_internal_options_to_dict(local_internal_options): - """ Create a dictionary with current local internal options. - - Args: - local_internal_options (List of str): A list containing local internal options. - """ - dict_local_internal_options= {} - no_comments_options = [line.strip() for line in local_internal_options - if not (line.startswith('#') or line == '\n')] - for line in no_comments_options: - key, value = line.split('=') - dict_local_internal_options[key.rstrip("\n")] = value - - return dict_local_internal_options - - def get_local_internal_options_dict(): """Return the local internal options in a dictionary. From 16bf442b37b859f0c1adf4ee180908050f6de342 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Rebollo?= Date: Tue, 7 Sep 2021 16:22:41 +0200 Subject: [PATCH 27/27] Remove unnused fixtures --- tests/integration/conftest.py | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index 497567c74a..55b51f355f 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -578,26 +578,6 @@ def put_env_variables(get_configuration, request): os.unsetenv(env[0]) -@pytest.fixture(scope="module") -def create_file_structure_module(get_files_list): - """Module scope version of create_file_structure.""" - create_file_structure(get_files_list) - - yield - - delete_file_structure(get_files_list) - - -@pytest.fixture(scope="function") -def create_file_structure_function(get_files_list): - """Function scope version of create_file_structure.""" - create_file_structure(get_files_list) - - yield - - delete_file_structure(get_files_list) - - @pytest.fixture(scope='module') def configure_local_internal_options_module(request): """Fixture to configure the local internal options file.