From e8d08af587ba94a83e8966f84bff8dfe8c961552 Mon Sep 17 00:00:00 2001 From: jmv74211 Date: Mon, 12 Sep 2022 12:04:25 +0200 Subject: [PATCH] refactor(#2947): Move analysisd fixtures to integration conftest --- tests/integration/conftest.py | 37 +++++++++++++ .../all_disabled_ossec.conf} | 0 .../test_analysisd/test_eps/conftest.py | 52 +------------------ ...t_process_old_events_instead_new_events.py | 4 +- 4 files changed, 40 insertions(+), 53 deletions(-) rename tests/integration/{test_analysisd/test_eps/data/wazuh_basic_configuration/ossec.conf => data/all_disabled_ossec.conf} (100%) diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index b272aac5de..55b9ee828b 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -26,6 +26,7 @@ from wazuh_testing import mocking from wazuh_testing.db_interface.agent_db import update_os_info from wazuh_testing.db_interface.global_db import get_system, modify_system +from wazuh_testing.tools.run_simulator import simulate_agent,syslog_simulator if sys.platform == 'win32': @@ -1188,3 +1189,39 @@ def create_file(new_file_path): yield remove_file(new_file_path) + + +@pytest.fixture(scope='function') +def simulate_agent_function(request): + """Fixture to run the script simulate_agent.py""" + simulate_agent(request.param) + + yield + + +@pytest.fixture(scope='session') +def load_wazuh_basic_configuration(): + """Load a new basic configuration to the manager""" + # Load ossec.conf with all disabled settings + minimal_configuration = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'data', 'all_disabled_ossec.conf') + + # Make a backup from current configuration + backup_ossec_configuration = get_wazuh_conf() + + # Write new configuration + with open(minimal_configuration, 'r') as file: + lines = file.readlines() + write_wazuh_conf(lines) + + yield + + # Restore the ossec.conf backup + write_wazuh_conf(backup_ossec_configuration) + + +@pytest.fixture(scope='function') +def syslog_simulator_function(request): + """Fixture to run the script syslog_simulator.py""" + syslog_simulator(request.param) + + yield diff --git a/tests/integration/test_analysisd/test_eps/data/wazuh_basic_configuration/ossec.conf b/tests/integration/data/all_disabled_ossec.conf similarity index 100% rename from tests/integration/test_analysisd/test_eps/data/wazuh_basic_configuration/ossec.conf rename to tests/integration/data/all_disabled_ossec.conf diff --git a/tests/integration/test_analysisd/test_eps/conftest.py b/tests/integration/test_analysisd/test_eps/conftest.py index 8ae42e3093..0adcd2f0ec 100644 --- a/tests/integration/test_analysisd/test_eps/conftest.py +++ b/tests/integration/test_analysisd/test_eps/conftest.py @@ -1,36 +1,13 @@ # 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.tools.services import control_service from wazuh_testing.tools import configuration -from wazuh_testing.tools.run_simulator import simulate_agent,syslog_simulator @pytest.fixture(scope='function') -def set_wazuh_configuration_analysisd(configuration, set_wazuh_configuration, configure_local_internal_options_eps): - """Set wazuh configuration - - Args: - configuration (dict): Configuration template data to write in the ossec.conf. - set_wazuh_configuration (fixture): Set the wazuh configuration according to the configuration data. - configure_local_internal_options_eps (fixture): Set the local_internal_options.conf file. - """ - yield - - -@pytest.fixture(scope='function') -def simulate_agent_function(request): - """Fixture to run the script simulate_agent.py""" - simulate_agent(request.param) - - yield - - -@pytest.fixture(scope='function') -def configure_wazuh_one_thread(): +def configure_analysisd_one_thread(): """Fixture to configure the local internal options file to work with one thread.""" local_internal_options = {'analysisd.event_threads': '1', 'analysisd.syscheck_threads': '1', 'analysisd.syscollector_threads': '1', 'analysisd.rootcheck_threads': '1', @@ -48,30 +25,3 @@ def configure_wazuh_one_thread(): # Backup the old local internal options cofiguration configuration.set_wazuh_local_internal_options(backup_local_internal_options) - - -@pytest.fixture(scope='session') -def load_wazuh_basic_configuration(): - """Load a new basic configuration to the manager""" - # Reference paths - DATA_PATH = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'data') - CONFIGURATIONS_PATH = os.path.join(DATA_PATH, 'wazuh_basic_configuration') - configurations_path = os.path.join(CONFIGURATIONS_PATH, 'ossec.conf') - - backup_ossec_configuration = configuration.get_wazuh_conf() - - with open(configurations_path, 'r') as file: - lines = file.readlines() - configuration.write_wazuh_conf(lines) - - yield - - configuration.write_wazuh_conf(backup_ossec_configuration) - - -@pytest.fixture(scope='function') -def syslog_simulator_function(request): - """Fixture to run the script syslog_simulator.py""" - syslog_simulator(request.param) - - yield diff --git a/tests/integration/test_analysisd/test_eps/test_process_old_events_instead_new_events.py b/tests/integration/test_analysisd/test_eps/test_process_old_events_instead_new_events.py index ccfdb98004..6d5c2d2f50 100644 --- a/tests/integration/test_analysisd/test_eps/test_process_old_events_instead_new_events.py +++ b/tests/integration/test_analysisd/test_eps/test_process_old_events_instead_new_events.py @@ -66,7 +66,7 @@ @pytest.mark.parametrize('configure_local_internal_options_module', local_internal_configuration_t1, indirect=True) @pytest.mark.parametrize('syslog_simulator_function', [params_process_old_events_one_thread], indirect=True) def test_process_old_events_one_thread(configuration, metadata, load_wazuh_basic_configuration, - configure_local_internal_options_module, configure_wazuh_one_thread, + configure_local_internal_options_module, configure_analysisd_one_thread, truncate_monitored_files, restart_wazuh_daemon_function, syslog_simulator_function): ''' @@ -99,7 +99,7 @@ def test_process_old_events_one_thread(configuration, metadata, load_wazuh_basic - set_wazuh_configuration_analysisd: type: fixture brief: Set the wazuh configuration according to the configuration data. - - configure_wazuh_one_thread: + - configure_analysisd_one_thread: type: fixture brief: Set the wazuh internal option configuration according to the configuration data. - truncate_monitored_files: