Skip to content

Commit

Permalink
Merge pull request #23608 from wazuh/test/23201-windows-agent-auth-en…
Browse files Browse the repository at this point in the history
…rollment

Corrections on conf and replacing timeout like agentd enrollment test
  • Loading branch information
vikman90 committed Jun 13, 2024
2 parents 9177943 + 8a5c3e4 commit a90065a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
2 changes: 0 additions & 2 deletions tests/integration/test_enrollment/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ def configure_socket_listener(request, test_metadata):
"""
Configures the socket listener to start listening on the socket.
"""
address_family = 'AF_INET6' if 'ipv6' in test_metadata else 'AF_INET'
manager_address = '::1' if 'ipv6' in test_metadata else MANAGER_ADDRESS

address_family = 'AF_INET6' if 'ipv6' in test_metadata else 'AF_INET'
manager_address = '::1' if 'ipv6' in test_metadata else MANAGER_ADDRESS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,12 @@
'''
import sys
import pytest
import time

from pathlib import Path

from wazuh_testing.constants.paths.logs import WAZUH_LOG_PATH
from wazuh_testing.constants.platforms import WINDOWS
from wazuh_testing.utils.configuration import get_test_cases_data, load_configuration_template
from wazuh_testing.tools.monitors import queue_monitor
from wazuh_testing.tools.monitors.file_monitor import FileMonitor
Expand All @@ -70,6 +72,15 @@

daemons_handler_configuration = {'all_daemons': True}

def launch_agent_with_retry(configuration, retries=5, delay=1):
for attempt in range(retries):
try:
return launch_agent_auth(configuration)
except Exception as e:
if attempt < retries - 1:
time.sleep(delay)
else:
pytest.xfail(f"Xfailing agent-auth start with error {e} after {retries} retries")

# Test function.
@pytest.mark.parametrize('test_configuration, test_metadata', zip(test_configuration, test_metadata), ids=cases_ids)
Expand Down Expand Up @@ -125,9 +136,9 @@ def test_agent_auth_enrollment(test_configuration, test_metadata, set_wazuh_conf
- Error logs related to the wrong configuration block
"""

launch_agent_auth(test_metadata.get('configuration', {}))

if 'expected_error' in test_metadata:
launch_agent_auth(test_metadata.get('configuration', {}))

expected_error_dict = test_metadata['expected_error']
expected_error = expected_error_dict['agent-auth'] if 'agent-auth' in expected_error_dict else \
expected_error_dict
Expand All @@ -147,6 +158,8 @@ def test_agent_auth_enrollment(test_configuration, test_metadata, set_wazuh_conf
raise error

else:
launch_agent_with_retry(test_metadata.get('configuration', {}))

test_expected = test_metadata['message']['expected'].format(host_name=get_host_name(),
agent_version=get_version()).encode()
test_response = test_metadata['message']['response'].format(host_name=get_host_name()).encode()
Expand All @@ -157,7 +170,7 @@ def test_agent_auth_enrollment(test_configuration, test_metadata, set_wazuh_conf

try:
# Start socket monitoring
socket_monitor.start(timeout=10, accumulations=2, callback=lambda received_event: received_event.encode() in event)
socket_monitor.start(timeout=60 if sys.platform == WINDOWS else 20, accumulations=2, callback=lambda received_event: received_event.encode() in event)

assert socket_monitor.matches == 2
except Exception as error:
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_enrollment/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,4 @@ def launch_agent_auth(test_configuration):
if test_configuration.get('groups'):
parser.add_groups(test_configuration.get('groups'))

subprocess.call(parser.get_command(), timeout=AGENT_AUTH_LAUNCH_TIMEOUT)
return subprocess.call(parser.get_command(), timeout=AGENT_AUTH_LAUNCH_TIMEOUT)

0 comments on commit a90065a

Please sign in to comment.