diff --git a/CHANGELOG.md b/CHANGELOG.md index a227b50f58..04651bc111 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ All notable changes to this project will be documented in this file. Wazuh commit: TBD \ Release report: TBD +### Fixed + +- Enhancing the handling of authd and remoted simulators in case of restart failures ([#Wazuh-jenkins#3487](https://github.com/wazuh/wazuh-qa/pull/4205)) \- (Tests) + ## [4.5.2] - TBD Wazuh commit: TBD \ diff --git a/tests/integration/test_active_response/test_execd/test_execd_firewall_drop.py b/tests/integration/test_active_response/test_execd/test_execd_firewall_drop.py index f8ef5458ee..086ea33e81 100644 --- a/tests/integration/test_active_response/test_execd/test_execd_firewall_drop.py +++ b/tests/integration/test_active_response/test_execd/test_execd_firewall_drop.py @@ -110,6 +110,7 @@ def start_agent(request, get_configuration): Args: get_configuration (fixture): Get configurations from the module. """ + agent_restart_failure = False metadata = get_configuration['metadata'] authd_simulator = AuthdSimulator(server_address=SERVER_ADDRESS, enrollment_port=1515, @@ -130,16 +131,22 @@ def start_agent(request, get_configuration): truncate_file(CLIENT_KEYS_PATH) time.sleep(1) - control_service('stop') - agent_auth_pat = 'bin' if platform.system() == 'Linux' else '' - call([f'{WAZUH_PATH}/{agent_auth_pat}/agent-auth', '-m', SERVER_ADDRESS]) - control_service('start') + try: + control_service('stop') + agent_auth_pat = 'bin' if platform.system() == 'Linux' else '' + call([f'{WAZUH_PATH}/{agent_auth_pat}/agent-auth', '-m', SERVER_ADDRESS]) + control_service('start') - yield + except Exception: + print("Failure to restart the agent") + agent_restart_failure = True + + yield agent_restart_failure remoted_simulator.stop() authd_simulator.shutdown() + @pytest.fixture(scope="function") def remove_ip_from_iptables(request, get_configuration): """Remove the testing IP address from `iptables` if it exists. @@ -279,6 +286,9 @@ def test_execd_firewall_drop(set_debug_mode, get_configuration, test_version, co tags: - simulator ''' + # Check if the agent is restarted properly" + assert not start_agent, 'The agent failed to restart successfully after enrolling the authentication simulator.' + metadata = get_configuration['metadata'] expected = metadata['results'] ossec_log_monitor = FileMonitor(LOG_FILE_PATH) diff --git a/tests/integration/test_active_response/test_execd/test_execd_restart.py b/tests/integration/test_active_response/test_execd/test_execd_restart.py index ed53091b57..f93fcfab36 100644 --- a/tests/integration/test_active_response/test_execd/test_execd_restart.py +++ b/tests/integration/test_active_response/test_execd/test_execd_restart.py @@ -105,6 +105,7 @@ def start_agent(request, get_configuration): Args: get_configuration (fixture): Get configurations from the module. """ + agent_restart_failure = False metadata = get_configuration['metadata'] authd_simulator = AuthdSimulator(server_address=SERVER_ADDRESS, enrollment_port=1515, @@ -125,13 +126,18 @@ def start_agent(request, get_configuration): truncate_file(CLIENT_KEYS_PATH) time.sleep(1) - control_service('stop') - agent_auth_pat = 'bin' if platform.system() == 'Linux' else '' - subprocess.call([f'{WAZUH_PATH}/{agent_auth_pat}/agent-auth', '-m', - SERVER_ADDRESS]) - control_service('start') + try: + control_service('stop') + agent_auth_pat = 'bin' if platform.system() == 'Linux' else '' + subprocess.call([f'{WAZUH_PATH}/{agent_auth_pat}/agent-auth', '-m', + SERVER_ADDRESS]) + control_service('start') - yield + except Exception: + print("Failure to restart the agent") + agent_restart_failure = True + + yield agent_restart_failure remoted_simulator.stop() authd_simulator.shutdown() @@ -230,6 +236,10 @@ def test_execd_restart(set_debug_mode, get_configuration, test_version, tags: - simulator ''' + + # Check if the agent is restarted properly" + assert not start_agent, 'The agent failed to restart successfully after enrolling the authentication simulator.' + metadata = get_configuration['metadata'] expected = metadata['results'] ossec_log_monitor = FileMonitor(LOG_FILE_PATH) diff --git a/tests/integration/test_enrollment/conftest.py b/tests/integration/test_enrollment/conftest.py index 20faa79801..ff2a13beb7 100644 --- a/tests/integration/test_enrollment/conftest.py +++ b/tests/integration/test_enrollment/conftest.py @@ -63,6 +63,7 @@ def configure_socket_listener(request, get_current_test_case): """ Configures the socket listener to start listening on the socket. """ + socket_listener_opened = True if 'message' in get_current_test_case and 'response' in get_current_test_case['message']: response = get_current_test_case['message']['response'].format(host_name=get_host_name()).encode() else: @@ -80,22 +81,28 @@ def configure_socket_listener(request, get_current_test_case): def receiver_callback(received_event): return response if not expected or expected == received_event else "".encode() - socket_listener = ManInTheMiddle(address=(manager_address, MANAGER_PORT), family=address_family, - connection_protocol='SSL', func=receiver_callback) - socket_listener.start() - socket_listener.listener.set_ssl_configuration(connection_protocol=ssl.PROTOCOL_TLSv1_2, - certificate=AGENT_CERT_PATH, - keyfile=AGENT_KEY_PATH, - options=None, - cert_reqs=ssl.CERT_OPTIONAL) + try: + socket_listener = ManInTheMiddle(address=(manager_address, MANAGER_PORT), family=address_family, + connection_protocol='SSL', func=receiver_callback) - while not socket_listener.queue.empty(): - socket_listener.queue.get_nowait() - socket_listener.event.clear() + socket_listener.start() + socket_listener.listener.set_ssl_configuration(connection_protocol=ssl.PROTOCOL_TLSv1_2, + certificate=AGENT_CERT_PATH, + keyfile=AGENT_KEY_PATH, + options=None, + cert_reqs=ssl.CERT_OPTIONAL) - setattr(request.module, 'socket_listener', socket_listener) + while not socket_listener.queue.empty(): + socket_listener.queue.get_nowait() + socket_listener.event.clear() - yield + setattr(request.module, 'socket_listener', socket_listener) + + except Exception: + print("Unexpected exception occurred during Man In the Middle initialization") + socket_listener_opened = False + + yield socket_listener_opened socket_listener.shutdown() diff --git a/tests/integration/test_enrollment/test_agent_auth_enrollment.py b/tests/integration/test_enrollment/test_agent_auth_enrollment.py index 9397c031c3..30374ef32e 100644 --- a/tests/integration/test_enrollment/test_agent_auth_enrollment.py +++ b/tests/integration/test_enrollment/test_agent_auth_enrollment.py @@ -141,6 +141,9 @@ def test_agent_auth_enrollment(configure_environment, shutdown_agentd, get_curre - Error logs related to the wrong configuration block """ + # Check if socket listener is opened + assert configure_socket_listener, 'The agent failed configuring socket listener to start listening on the socket.' + if 'agent-auth' in get_current_test_case.get('skips', []): pytest.skip('This test does not apply to agent-auth') diff --git a/tests/integration/test_enrollment/test_agentd_enrollment.py b/tests/integration/test_enrollment/test_agentd_enrollment.py index f85762c2c2..b2c26d97ab 100644 --- a/tests/integration/test_enrollment/test_agentd_enrollment.py +++ b/tests/integration/test_enrollment/test_agentd_enrollment.py @@ -154,6 +154,9 @@ def test_agentd_enrollment(configure_environment, override_wazuh_conf, get_curre - Error logs related to the wrong configuration block """ + # Check if socket listener is opened + assert configure_socket_listener, 'The agent failed configuring socket listener to start listening on the socket.' + if 'expected_error' in get_current_test_case: log_monitor = request.module.log_monitor expected_error_dict = get_current_test_case['expected_error'] diff --git a/tests/integration/test_enrollment/test_agentd_server_address_configuration.py b/tests/integration/test_enrollment/test_agentd_server_address_configuration.py index b75fb0e3f7..48add44e31 100644 --- a/tests/integration/test_enrollment/test_agentd_server_address_configuration.py +++ b/tests/integration/test_enrollment/test_agentd_server_address_configuration.py @@ -184,6 +184,9 @@ def test_agentd_server_address_configuration(configure_local_internal_options_mo - agentd ''' + # Check if socket listener is opened + assert configure_socket_listener, 'The agent failed configuring socket listener to start listening on the socket.' + cfg = get_configuration['metadata'] manager_address = cfg['server_address']