Skip to content

Commit

Permalink
Merge pull request #2627 from wazuh/wazuhdb-getconfig
Browse files Browse the repository at this point in the history
IT - WDB - 2532- Test wazuh-DB getconfig WDB command
  • Loading branch information
damarisg authored Mar 4, 2022
2 parents e3e4daf + 077977d commit 7f77d61
Show file tree
Hide file tree
Showing 4 changed files with 152 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Wazuh commit: TBD \
Release report: TBD

### Added

- Test `wazuhdb getconfig` WDB command ([2627#](https://github.com/wazuh/wazuh-qa/pull/2627))
- Test `get-groups-integrity` WDB command ([#2607](https://github.com/wazuh/wazuh-qa/pull/2607))
- Test `set-agent-groups` WDB command ([#2602](https://github.com/wazuh/wazuh-qa/pull/2602))
- Add test fim with file currently open ([#2300](https://github.com/wazuh/wazuh-qa/pull/2300))
Expand Down
17 changes: 17 additions & 0 deletions deps/wazuh_testing/wazuh_testing/tools/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,22 @@ def read_yaml(file_path):
return yaml.safe_load(f)


def get_list_of_content_yml(file_path, filter, list=[]):
"""Read a YAML file from a given path, return a list with the YAML data
after apply filter
Args:
file_path (str): Path of the YAML file to be readed
filter (str): filder to extract some part of yaml
list: a list with previous information
Returns:
list: Yaml structure.
"""
list.append((read_yaml(file_path), file_path + filter))
return list


def truncate_file(file_path):
"""
Truncate a file to reset its content.
Expand Down Expand Up @@ -485,3 +501,4 @@ def download_text_file(file_url, local_destination_path):
raise ValueError(f"The remote url {file_url} does not have text/plain content type to download it")

open(local_destination_path, 'wb').write(request.content)

31 changes: 31 additions & 0 deletions tests/integration/test_wazuh_db/data/global/wazuhdb_getconfig.yaml
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 tests/integration/test_wazuh_db/test_wazuhdb_getconfig.py
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

0 comments on commit 7f77d61

Please sign in to comment.