-
Notifications
You must be signed in to change notification settings - Fork 32
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 #2627 from wazuh/wazuhdb-getconfig
IT - WDB - 2532- Test wazuh-DB getconfig WDB command
- Loading branch information
Showing
4 changed files
with
152 additions
and
1 deletion.
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
31 changes: 31 additions & 0 deletions
31
tests/integration/test_wazuh_db/data/global/wazuhdb_getconfig.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,31 @@ | ||
--- | ||
- | ||
name: 'Get config missing parameter' | ||
test_case: | ||
- | ||
input: 'wazuhdb getconfig' | ||
output: "err Invalid DB query syntax, near 'getconfig'" | ||
- | ||
name: 'Get config empty parameter' | ||
test_case: | ||
- | ||
input: 'wazuhdb getconfig ' | ||
output: 'err Failed reading wazuh-db config' | ||
- | ||
name: 'Get config wrong parameter' | ||
test_case: | ||
- | ||
input: 'wazuhdb getconfig wrong_parameter' | ||
output: 'err Failed reading wazuh-db config' | ||
- | ||
name: 'Get internal config' | ||
test_case: | ||
- | ||
input: 'wazuhdb getconfig internal' | ||
output: "{'wazuh_db': {'commit_time_max': 60, 'commit_time_min': 10, 'open_db_limit': 64, 'sock_queue_size': 128, 'worker_pool_size': 8}}" | ||
- | ||
name: 'Get wdb config' | ||
test_case: | ||
- | ||
input: 'wazuhdb getconfig wdb' | ||
output: "{'wdb': {'backup': [{'database': 'global', 'enabled': True, 'interval': 86400, 'max_files': 3}]}}" |
103 changes: 103 additions & 0 deletions
103
tests/integration/test_wazuh_db/test_wazuhdb_getconfig.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 @@ | ||
''' | ||
copyright: Copyright (C) 2015-2022, Wazuh Inc. | ||
Created by Wazuh, Inc. <info@wazuh.com>. | ||
This program is free software; you can redistribute it and/or modify it under the terms of GPLv2 | ||
type: integration | ||
brief: Wazuh-db is the daemon in charge of the databases with all the Wazuh persistent information, exposing a socket | ||
to receive requests and provide information. The Wazuh core uses list-based databases to store information | ||
related to agent keys, and FIM/Rootcheck event data. | ||
This test checks the usage of the wazuhdb getconfig command used to get the current configuration | ||
tier: 0 | ||
modules: | ||
- wazuh_db | ||
components: | ||
- manager | ||
daemons: | ||
- wazuh-db | ||
os_platform: | ||
- linux | ||
os_version: | ||
- Arch Linux | ||
- Amazon Linux 2 | ||
- Amazon Linux 1 | ||
- CentOS 8 | ||
- CentOS 7 | ||
- CentOS 6 | ||
- Ubuntu Focal | ||
- Ubuntu Bionic | ||
- Ubuntu Xenial | ||
- Ubuntu Trusty | ||
- Debian Buster | ||
- Debian Stretch | ||
- Debian Jessie | ||
- Debian Wheezy | ||
- Red Hat 8 | ||
- Red Hat 7 | ||
- Red Hat 6 | ||
references: | ||
- https://documentation.wazuh.com/current/user-manual/reference/daemons/wazuh-db.html | ||
tags: | ||
- wazuh_db | ||
''' | ||
import os | ||
import pytest | ||
import yaml | ||
from wazuh_testing.tools import WAZUH_PATH | ||
from wazuh_testing.wazuh_db import query_wdb | ||
from wazuh_testing.tools.file import get_list_of_content_yml | ||
|
||
|
||
# Marks | ||
pytestmark = [pytest.mark.linux, pytest.mark.tier(level=0), pytest.mark.server] | ||
|
||
# Configurations | ||
test_data_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'data') | ||
messages_file = os.path.join(os.path.join(test_data_path, 'global'), 'wazuhdb_getconfig.yaml') | ||
module_tests = get_list_of_content_yml(messages_file, ".split('_')[0]") | ||
|
||
log_monitor_paths = [] | ||
wdb_path = os.path.join(os.path.join(WAZUH_PATH, 'queue', 'db', 'wdb')) | ||
receiver_sockets_params = [(wdb_path, 'AF_UNIX', 'TCP')] | ||
monitored_sockets_params = [('wazuh-db', None, True)] | ||
receiver_sockets = None # Set in the fixtures | ||
|
||
|
||
# Tests | ||
@pytest.mark.parametrize('test_case', | ||
[case['test_case'] for module_data in module_tests for case in module_data[0]], | ||
ids=[f"{module_name}: {case['name']}" | ||
for module_data, module_name in module_tests | ||
for case in module_data] | ||
) | ||
def test_sync_agent_groups(configure_sockets_environment, connect_to_sockets_module, test_case): | ||
''' | ||
description: Check that commands about wazuhdb getconfig works properly. | ||
wazuh_min_version: 4.4.0 | ||
parameters: | ||
- configure_sockets_environment: | ||
type: fixture | ||
brief: Configure environment for sockets and MITM. | ||
- connect_to_sockets_module: | ||
type: fixture | ||
brief: Module scope version of 'connect_to_sockets' fixture. | ||
- test_case: | ||
type: fixture | ||
brief: List of test_case stages (dicts with input, output and agent_id and expected_groups keys). | ||
assertions: | ||
- Verify that the socket response matches the expected output. | ||
input_description: | ||
- Test cases are defined in the wazuhdb_getconfig.yaml file. | ||
expected_output: | ||
- an array with the configuration of DB. | ||
tags: | ||
- wazuh_db | ||
- wdb_socket | ||
''' | ||
# Set each case | ||
case_data = test_case[0] | ||
output = case_data["output"] | ||
|
||
response = query_wdb(case_data["input"]) | ||
|
||
# Validate response | ||
assert str(response) == output |