Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix test_synchronization system test #5089

Merged
merged 5 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions tests/system/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@


# Functions
def get_agent_id(host_manager):
def get_agent_id(host_manager, node='wazuh-master'):
# Gets the first agent id in the master's client.keys file
return host_manager.run_command('wazuh-master', f'cut -c 1-3 {WAZUH_PATH}/etc/client.keys')
return host_manager.run_command(node, f'cut -c 1-3 {WAZUH_PATH}/etc/client.keys')


def get_id_from_agent(agent, host_manager):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@
- name: Start Wazuh
command: /var/ossec/bin/wazuh-control restart

- name: Create script to check BD
- name: Copy wdb-query.py script
copy:
src: ../../../../../scripts/system_query_db.py
dest: /var/
src: ../../../../scripts/wdb-query.py
dest: /var/ossec/bin/wdb-query.py
owner: root
group: root
mode: '0644'
13 changes: 0 additions & 13 deletions tests/system/scripts/system_query_db.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,16 @@
"""

import os
import json
import pytest
import re
from time import sleep


from system import execute_wdb_query, get_agent_id
from wazuh_testing.tools.system_monitoring import HostMonitor
from wazuh_testing.tools.system import HostManager, clean_environment
from wazuh_testing.tools import WAZUH_LOGS_PATH
from wazuh_testing.fim import create_folder_file, query_db
from wazuh_testing.fim import create_folder_file


pytestmark = [pytest.mark.one_manager_agent_env]
Expand All @@ -67,8 +68,6 @@
]
tmp_path = os.path.join(local_path, 'tmp')
scheduled_mode = 'testdir1'
db_path = '/var/ossec/queue/db/001.db'
db_script = '/var/system_query_db.py'
enviroment_files = [('wazuh-manager', os.path.join(WAZUH_LOGS_PATH, 'ossec.log')),
('wazuh-agent1', os.path.join(WAZUH_LOGS_PATH, 'ossec.log'))]

Expand Down Expand Up @@ -136,6 +135,7 @@ def test_synchronization(folder_path, case, host):
host_manager.run_command('wazuh-agent1', f'rm -rf {folder_path}')
folder_path = f"'/{folder_path}/{folder_path}.txt'"
query = " select * from fim_entry where full_path='\"{}\"'".format(folder_path)
agent_id = get_agent_id(host_manager, 'wazuh-manager')

# Start host
host_manager.run_command(host, '/var/ossec/bin/wazuh-control start')
Expand All @@ -150,8 +150,9 @@ def test_synchronization(folder_path, case, host):
if (case == 'delete'):
# Execute query to DB
sleep(5)
result = query_db(host_manager, db_script, db_path, f'\"{query}\"')
assert not json.loads(result)
result = execute_wdb_query(f"{agent_id} {query}", 'wazuh-manager', host_manager)

assert result == '[]'

finally:
host_manager.run_command('wazuh-agent1', f'rm -rf {folder_path}')
Loading