Skip to content

Commit

Permalink
Merge branch 'master' into 2434-fim-synchronizaton-agent-stopped
Browse files Browse the repository at this point in the history
  • Loading branch information
CamiRomero authored Feb 11, 2022
2 parents 7302810 + b8ea5e7 commit 96bad3e
Show file tree
Hide file tree
Showing 79 changed files with 10,697 additions and 11,065 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ Release report: TBD
- Add system test to check synchronization between agent and manager when one of this was stopped. ([#2536](https://github.com/wazuh/wazuh-qa/pull/2536))

### Changed
- Fix the unstable FIM tests that need refactoring. ([#2421](https://github.com/wazuh/wazuh-qa/pull/2458))
- Refactor: FIM `test_synchronization` according to new standard. Phase 1. ([#2358](https://github.com/wazuh/wazuh-qa/pull/2358))
- Skip : FIM `test_registry_limit_values` until expected message is added to Windows Agent ([#2446](https://github.com/wazuh/wazuh-qa/pull/2446))
- Adapt logtest ITs given the rules skipping ([#2146](https://github.com/wazuh/wazuh-qa/pull/2146))
- Fix version validation in qa-ctl config generator ([#2454](https://github.com/wazuh/wazuh-qa/pull/2454))
- Migrate test_age, test_command_monitoring, and test_keep_running of test_logcollector documentation to qa-docs ([#2162](https://github.com/wazuh/wazuh-qa/pull/2162))
Expand All @@ -27,6 +30,7 @@ Release report: TBD
- Migrate several test groups of test_logcollector documentation to qa-docs ([#2180](https://github.com/wazuh/wazuh-qa/pull/2180))
- Add wpk test documentation ([#2409](https://github.com/wazuh/wazuh-qa/pull/2409))
- Migrate test_remoted documentation to schema 2.0 ([#2426](https://github.com/wazuh/wazuh-qa/pull/2426))
- Fix FIM test: Replace callback_generator function to generate_monitoring_callback ([#2535](https://github.com/wazuh/wazuh-qa/pull/2535))


### Deleted
Expand All @@ -41,6 +45,7 @@ Release report: https://github.com/wazuh/wazuh-qa/issues/2500
### Added

- Added specific version of libcst to install in python lower than 3.7. ([#2459](https://github.com/wazuh/wazuh-qa/pull/2459))
- Add system test to check synchronization between agent and manager. ([#2443](https://github.com/wazuh/wazuh-qa/pull/2443))
- Make `simulate-api-load` CLI run tasks simultaneously. ([#2392](https://github.com/wazuh/wazuh-qa/pull/2392))
- Add `qa-ctl` `v0.3`. ([#2307](https://github.com/wazuh/wazuh-qa/pull/2307))
- Add `qa-ctl` `v0.2`. ([#2299](https://github.com/wazuh/wazuh-qa/pull/2299))
Expand Down
25 changes: 24 additions & 1 deletion deps/wazuh_testing/wazuh_testing/db_interface/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
import socket
import os
import sqlite3
from time import sleep

from wazuh_testing.tools.monitoring import wazuh_pack, wazuh_unpack
from wazuh_testing.tools.services import control_service
import wazuh_testing


Expand All @@ -22,12 +24,33 @@ def query_wdb(command):
Returns:
list: Query response data.
"""
# If the wdb socket is not yet up, then wait or restart wazuh-db
if not os.path.exists(WAZUH_DB_SOCKET_PATH):
max_retries = 6
for _ in range(2):
retry = 0
# Wait if the wdb socket is not still alive (due to wazuh-db restarts). Max 3 seconds
while not os.path.exists(WAZUH_DB_SOCKET_PATH) and retry < max_retries:
print("Retrying ...")
sleep(0.5)
retry += 1

# Restart wazuh-db in case of wdb socket is not yet up.
if not os.path.exists(WAZUH_DB_SOCKET_PATH):
print("Restarting wazuh-db ...")
control_service('restart', daemon='wazuh-db')

# Raise custom exception if the socket is not up in the expected time, even restarting wazuh-db
if not os.path.exists(WAZUH_DB_SOCKET_PATH):
raise Exception('The wdb socket is not up. wazuh-db was restarted but the socket was not found')

# Create and open the socket connection with wazuh-db socket
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
sock.connect(WAZUH_DB_SOCKET_PATH)

data = []

try:
# Send the query request
sock.send(wazuh_pack(len(command)) + command.encode())

rcv = sock.recv(4)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from wazuh_testing.fim import LOG_FILE_PATH, callback_detect_registry_integrity_state_event
from wazuh_testing import global_parameters
from wazuh_testing.fim_module.fim_variables import MAX_EVENTS_VALUE, CB_REGISTRY_DBSYNC_NO_DATA
from wazuh_testing.tools.monitoring import FileMonitor, callback_generator
from wazuh_testing.tools.monitoring import FileMonitor, generate_monitoring_callback


def get_sync_msgs(tout, new_data=True):
Expand All @@ -24,7 +24,7 @@ def get_sync_msgs(tout, new_data=True):
events = []
if new_data:
wazuh_log_monitor.start(timeout=tout,
callback=callback_generator(CB_REGISTRY_DBSYNC_NO_DATA),
callback=generate_monitoring_callback(CB_REGISTRY_DBSYNC_NO_DATA),
error_message='Did not receive expected '
'"db sync no data" event')
for _ in range(0, MAX_EVENTS_VALUE):
Expand Down
3 changes: 3 additions & 0 deletions deps/wazuh_testing/wazuh_testing/tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
ANALYSIS_STATISTICS_FILE = None
UPGRADE_PATH = os.path.join(WAZUH_PATH, 'upgrade')
AGENT_AUTH_BINARY_PATH = os.path.join(WAZUH_PATH, 'agent-auth.exe')
WAZUH_UNIX_USER = 'wazuh'
WAZUH_UNIX_GROUP = 'wazuh'
GLOBAL_DB_PATH = os.path.join(WAZUH_PATH, 'queue', 'db', 'global.db')

else:

Expand Down
1 change: 0 additions & 1 deletion deps/wazuh_testing/wazuh_testing/tools/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,4 +261,3 @@ def clean_environment(host_manager, target_files):
"""
for target in target_files:
host_manager.clear_file(host=target[0], file_path=target[1])

14 changes: 14 additions & 0 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
from wazuh_testing.tools.monitoring import QueueMonitor, FileMonitor, SocketController, close_sockets
from wazuh_testing.tools.services import control_service, check_daemon_status, delete_dbs
from wazuh_testing.tools.time import TimeMachine
from wazuh_testing.mocking import create_mocked_agent, delete_mocked_agent


if sys.platform == 'win32':
from wazuh_testing.fim import KEY_WOW64_64KEY, KEY_WOW64_32KEY, delete_registry, registry_parser, create_registry
Expand Down Expand Up @@ -850,3 +852,15 @@ 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 mock_agent_module():
"""
Fixture to create a mocked agent in wazuh databases
"""
agent_id = create_mocked_agent(name="mocked_agent")

yield agent_id

delete_mocked_agent(agent_id)
14 changes: 0 additions & 14 deletions tests/integration/test_analysisd/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,3 @@ def restart_analysisd():

for daemon in required_logtest_daemons:
control_service('stop', daemon=daemon)


@pytest.fixture(scope='module')
def mock_agent():
"""Fixture to create a mocked agent in wazuh databases"""
control_service('stop', daemon='wazuh-db')
agent_id = create_mocked_agent(name="mocked_agent")
control_service('start', daemon='wazuh-db')

yield agent_id

control_service('stop', daemon='wazuh-db')
delete_mocked_agent(agent_id)
control_service('start', daemon='wazuh-db')
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,14 @@
references:
- https://documentation.wazuh.com/current/user-manual/capabilities/syscollector.html#using-syscollector-information-to-trigger-alerts
'''
import json
import os

import pytest
import yaml
import pytest

from wazuh_testing.tools import (ANALYSISD_QUEUE_SOCKET_PATH, ALERT_FILE_PATH)
from wazuh_testing.analysis import CallbackWithContext, callback_check_syscollector_alert


# Marks
pytestmark = [pytest.mark.linux, pytest.mark.tier(level=0), pytest.mark.server]

Expand All @@ -88,10 +87,11 @@ def get_configuration(request):


# Tests
@pytest.mark.skip(reason='Temporarily disabled until merge this PR https://github.com/wazuh/wazuh/pull/10843')
@pytest.mark.parametrize('test_case',
list(test_cases),
ids=[test_case['name'] for test_case in test_cases])
def test_syscollector_events(test_case, get_configuration, mock_agent, configure_custom_rules, restart_analysisd,
def test_syscollector_events(test_case, get_configuration, mock_agent_module, configure_custom_rules, restart_analysisd,
wait_for_analysisd_startup, connect_to_sockets_function, file_monitoring):
'''
description:
Expand All @@ -104,7 +104,7 @@ def test_syscollector_events(test_case, get_configuration, mock_agent, configure
- get_configuration:
type: fixture
brief: Get configurations from the module.
- mock_agent:
- mock_agent_module:
type: fixture
brief: Create mock agent and get agent_id
- configure_custom_rules:
Expand Down Expand Up @@ -140,7 +140,7 @@ def test_syscollector_events(test_case, get_configuration, mock_agent, configure
'''

# Get mock agent_id to create syscollector header
agent_id = mock_agent
agent_id = mock_agent_module
event_header = f"d:[{agent_id}] {test_case['event_header']}"

for stage in test_case['test_case']:
Expand Down
Loading

0 comments on commit 96bad3e

Please sign in to comment.