-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1109 from wazuh/1102-manager-ack
Remoted integration tests T1: Add test manager ACK
- Loading branch information
Showing
8 changed files
with
213 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
docs/tests/integration/test_remoted/test_manager_messages/test_manager_ack.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# Test manager ACK | ||
|
||
## Overview | ||
|
||
These tests will check if the manager sends the ACK message after receiving the `start-up` message from agent. | ||
|
||
## Objective | ||
|
||
The objective is to check that the manager sends the ACK message using the different protocols. | ||
|
||
## General info | ||
|
||
|Tier | Number of tests | Time spent | | ||
|:--:|:--:|:--:| | ||
| 0 | 4 | 1m 15s | | ||
|
||
## Expected behavior | ||
|
||
Success if the agent receives the ACK message from the manager after sending the `start-up` message. Failure otherwise. | ||
|
||
## Testing | ||
|
||
The testing is based on configuring the manager to receive messages via `TCP`, `UDP`, `TCP-UDP` and `UDP-TCP`. | ||
|
||
First, the simulated agent will send the `start-up` message to the manager, and then, the agent will save all the | ||
incoming messages from the agent in a buffer. | ||
|
||
The `start-up` message sent by the agent is as follows: | ||
|
||
``` | ||
#!-agent startup | ||
``` | ||
|
||
Next, the test will search the ACK message in the agent buffer (it contains the string `#!-agent ack`). | ||
|
||
An example of the `ACK` message is as follows: | ||
|
||
``` | ||
4112dbb63510267c613d5b6da095b4ea274310000000010:2203:#!-agent ack | ||
``` | ||
|
||
### Checks | ||
|
||
- Manager sends the ACK message using `TCP` protocol. | ||
- Manager sends the ACK message using `UDP` protocol. | ||
- Manager sends the ACK message using `TCP,UDP` configuration. | ||
- Manager sends the ACK message using `UDP,TCP` configuration. | ||
|
||
## Comments | ||
|
||
An important aspect to take into account is the time needed by wazuh-remoted to reload the `client.keys`. | ||
By default it is **10 seconds**, but this option is configurable in the `internal_options.conf`, using the | ||
following directive: | ||
|
||
``` | ||
remoted.keyupdate_interval=2 | ||
``` | ||
|
||
The test itself waits until the info is loaded, so reducing this time will also reduce the test time. | ||
It is recommended to set this time between 2 and 5 seconds. | ||
|
||
## Code documentation | ||
::: tests.integration.test_remoted.test_manager_messages.test_manager_ack |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
tests/integration/test_remoted/test_manager_messages/data/wazuh_manager_ack.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
- tags: | ||
- test_manager_ack | ||
apply_to_modules: | ||
- test_manager_ack | ||
sections: | ||
- section: remote | ||
elements: | ||
- connection: | ||
value: secure | ||
- port: | ||
value: 1514 | ||
- protocol: | ||
value: PROTOCOL |
103 changes: 103 additions & 0 deletions
103
tests/integration/test_remoted/test_manager_messages/test_manager_ack.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import pytest | ||
import os | ||
import wazuh_testing.tools.agent_simulator as ag | ||
|
||
from time import sleep | ||
from wazuh_testing import remote as rd | ||
from wazuh_testing import is_tcp_udp | ||
from wazuh_testing.tools import LOG_FILE_PATH | ||
from wazuh_testing.tools.configuration import load_wazuh_configurations | ||
from wazuh_testing.tools.monitoring import FileMonitor | ||
|
||
|
||
# Marks | ||
pytestmark = pytest.mark.tier(level=1) | ||
|
||
# Variables | ||
current_test_path = os.path.dirname(os.path.realpath(__file__)) | ||
test_data_path = os.path.join(current_test_path, 'data') | ||
configurations_path = os.path.join(test_data_path, 'wazuh_manager_ack.yaml') | ||
|
||
wazuh_log_monitor = FileMonitor(LOG_FILE_PATH) | ||
|
||
# Set configuration | ||
parameters = [ | ||
{'PROTOCOL': 'tcp'}, | ||
{'PROTOCOL': 'udp'}, | ||
{'PROTOCOL': 'tcp,udp'}, | ||
{'PROTOCOL': 'udp,tcp'}, | ||
] | ||
|
||
metadata = [ | ||
{'protocol': 'tcp'}, | ||
{'protocol': 'udp'}, | ||
{'protocol': 'tcp,udp'}, | ||
{'protocol': 'udp,tcp'}, | ||
] | ||
|
||
agent_info = { | ||
'manager_address': '127.0.0.1', | ||
'os': 'debian7', | ||
'version': '4.2.0', | ||
'disable_all_modules': True | ||
} | ||
|
||
configuration_ids = [item['PROTOCOL'].upper() for item in parameters] | ||
|
||
# Configuration data | ||
configurations = load_wazuh_configurations(configurations_path, __name__, params=parameters, metadata=metadata) | ||
|
||
|
||
def check_manager_ack(protocol): | ||
"""Allow to check if the manager sends the ACK message after receiving the start-up message from agent. | ||
Args: | ||
protocol (str): It can be UDP or TCP. | ||
Raises: | ||
TimeoutError: If agent does not receive the manager ACK message in the expected time. | ||
""" | ||
|
||
# Create agent and sender object with default parameters | ||
agent = ag.Agent(**agent_info) | ||
|
||
# Sleep to avoid ConnectionRefusedError | ||
sleep(1) | ||
|
||
sender = ag.Sender(agent_info['manager_address'], protocol=protocol) | ||
|
||
# Activate receives_messages modules in simulated agent. | ||
agent.set_module_status('receive_messages', 'enabled') | ||
|
||
# Run injector with only receive messages module enabled | ||
injector = ag.Injector(sender, agent) | ||
try: | ||
injector.run() | ||
|
||
# Wait until remoted has loaded the new agent key | ||
rd.wait_to_remoted_key_update(wazuh_log_monitor) | ||
|
||
# Send the start-up message | ||
sender.send_event(agent.startup_msg) | ||
|
||
# Check ACK manager message | ||
rd.check_agent_received_message(agent.rcv_msg_queue, '#!-agent ack') | ||
finally: | ||
injector.stop_receive() | ||
|
||
|
||
@pytest.fixture(scope='module', params=configurations, ids=configuration_ids) | ||
def get_configuration(request): | ||
"""Get configurations from the module.""" | ||
return request.param | ||
|
||
|
||
def test_manager_ack(get_configuration, configure_environment, restart_remoted): | ||
"""Check if the manager sends the ACK message after receiving the start-up message from the agent.""" | ||
protocol = get_configuration['metadata']['protocol'] | ||
|
||
if is_tcp_udp(protocol): | ||
check_manager_ack(rd.TCP) | ||
check_manager_ack(rd.UDP) | ||
else: | ||
check_manager_ack(protocol) |