Skip to content

Commit

Permalink
Merge pull request #3146 from wazuh/fix-wdb-getconfig
Browse files Browse the repository at this point in the history
IT: Fix tests fails caused by stats socket changes
  • Loading branch information
jmv74211 authored Aug 25, 2022
2 parents 376ec59 + 6fd17c4 commit bbc1d89
Show file tree
Hide file tree
Showing 8 changed files with 124 additions and 89 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Release report: TBD

### Changed

- Update wazuhdb_getconfig integration tests ([#3146](https:/wazuh/wazuh-qa/pull/3146)) \- (Tests)
- Change how 'service_control' collects clusterd and apid pids ([#3140](https:/wazuh/wazuh-qa/pull/3140)) \- (Framework)
- Change scan test module fixtures to allow use commit instead of branches ([#3134](https:/wazuh/wazuh-qa/issues/3134)) \- (Tests)
- Update syscollector deltas integration tests ([#2921](https:/wazuh/wazuh-qa/pull/2921)) \- (Tests)
Expand Down
2 changes: 1 addition & 1 deletion deps/wazuh_testing/wazuh_testing/tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def get_service():
LOGCOLLECTOR_SOCKET_PATH = os.path.join(QUEUE_SOCKETS_PATH, 'logcollector')
LOGTEST_SOCKET_PATH = os.path.join(QUEUE_SOCKETS_PATH, 'logtest')
MONITORD_SOCKET_PATH = os.path.join(QUEUE_SOCKETS_PATH, 'monitor')
REMOTED_SOCKET_PATH = os.path.join(QUEUE_SOCKETS_PATH, 'request')
REMOTED_SOCKET_PATH = os.path.join(QUEUE_SOCKETS_PATH, 'remote')
SYSCHECKD_SOCKET_PATH = os.path.join(QUEUE_SOCKETS_PATH, 'syscheck')
WAZUH_DB_SOCKET_PATH = os.path.join(QUEUE_DB_PATH, 'wdb')
MODULESD_WMODULES_SOCKET_PATH = os.path.join(QUEUE_SOCKETS_PATH, 'wmodules')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@
logtest_sock = os.path.join(os.path.join(WAZUH_PATH, 'queue', 'sockets', 'analysis'))
receiver_sockets_params = [(logtest_sock, 'AF_UNIX', 'TCP')]
receiver_sockets = None
msg_get_config = "getconfig rule_test"
msg_get_config = '{"version": 1, "origin": {"module": "api"}, "command": "getconfig", "module": "api",\
"parameters": {"section": "rule_test"}}'


# Fixture
Expand All @@ -81,8 +82,8 @@ def test_get_configuration_sock(get_configuration, configure_environment, restar
description: Check analysis Unix socket returns the correct Logtest configuration under different sets of
configurations, `wazuh-analisysd` returns the right information from the `rule_test` configuration
block. To do this, it overwrites wrong field values and checks that the values within the received
message after establishing a connection using the logtest AF_UNIX socket that uses TCP are the same that the
loaded fields from the 'wazuh_conf.yaml' file.
message after establishing a connection using the logtest AF_UNIX socket that uses TCP are the same
that the loaded fields from the 'wazuh_conf.yaml' file.
wazuh_min_version: 4.2.0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,74 +1,95 @@
---
-
name: 'rules_debug_omitted'
rule_file: 'rules_verbose.xml'
name: rules_debug_omitted
rule_file: rules_verbose.xml
rule_id: '880002'
input: '{"version":1,"origin":{"name":"Integration Test","module":"api"},"command":"log_processing","parameters":{"event": "{\"it_logtest\" : \"rules_verbose\", \"test\": \"last_match\", \"test_child\" : \"ok\"}","log_format": "syslog","location": "master->/var/log/syslog"}}'
input: '{"version":1,"origin":{"name":"Integration Test","module":"api"},"command":"log_processing","parameters":{
"event": "{\"it_logtest\" : \"rules_verbose\", \"test\": \"last_match\", \"test_child\" : \"ok\"}",
"log_format": "syslog","location": "master->/var/log/syslog"}}'
-
name: 'rules_debug_true'
rule_file: 'rules_verbose.xml'
name: rules_debug_true
rule_file: rules_verbose.xml
rule_id: '880001'
input: '{"version":1,"origin":{"name":"Integration Test","module":"api"},"command":"log_processing","parameters":{"event": "{\"it_logtest\" : \"rules_verbose\", \"test\": \"last_match\"}","log_format": "syslog","location": "master->/var/log/syslog","options":{"rules_debug":true}}}'
verbose_mode: True
input: '{"version":1,"origin":{"name":"Integration Test","module":"api"},"command":"log_processing","parameters":{
"event": "{\"it_logtest\" : \"rules_verbose\", \"test\": \"last_match\"}","log_format": "syslog",
"location": "master->/var/log/syslog","options":{"rules_debug":true}}}'
verbose_mode: true
-
name: 'rules_debug_false'
rule_file: 'rules_verbose.xml'
name: rules_debug_false
rule_file: rules_verbose.xml
rule_id: '880001'
input: '{"version":1,"origin":{"name":"Integration Test","module":"api"},"command":"log_processing","parameters":{"event": "{\"it_logtest\" : \"rules_verbose\", \"test\": \"last_match\"}","log_format": "syslog","location": "master->/var/log/syslog","options":{"rules_debug":false}}}'
verbose_mode: False
input: '{"version":1,"origin":{"name":"Integration Test","module":"api"},"command":"log_processing","parameters":{
"event": "{\"it_logtest\" : \"rules_verbose\", \"test\": \"last_match\"}","log_format": "syslog",
"location": "master->/var/log/syslog","options":{"rules_debug":false}}}'
verbose_mode: false
-
name: 'rules_debug_bad_type_string'
rule_file: 'rules_verbose.xml'
name: rules_debug_bad_type_string
rule_file: rules_verbose.xml
rule_id: '880001'
input: '{"version":1,"origin":{"name":"Integration Test","module":"api"},"command":"log_processing","parameters":{"event": "{\"it_logtest\" : \"rules_verbose\", \"test\": \"last_match\"}","log_format": "syslog","location": "master->/var/log/syslog","options":{"rules_debug":"true"}}}'
verbose_mode: False
warning_message: "WARNING: \\(\\d+\\): 'rules_debug' field must be a boolean. The parameter will be ignored"
input: '{"version":1,"origin":{"name":"Integration Test","module":"api"},"command":"log_processing","parameters":{
"event": "{\"it_logtest\" : \"rules_verbose\", \"test\": \"last_match\"}","log_format": "syslog",
"location": "master->/var/log/syslog","options":{"rules_debug":"true"}}}'
verbose_mode: false
warning_message: ".*WARNING: .*: ('rules_debug' field must be a boolean. The parameter will be ignored).*"
-
name: 'rules_debug_bad_type_number'
rule_file: 'rules_verbose.xml'
name: rules_debug_bad_type_number
rule_file: rules_verbose.xml
rule_id: '880001'
input: '{"version":1,"origin":{"name":"Integration Test","module":"api"},"command":"log_processing","parameters":{"event": "{\"it_logtest\" : \"rules_verbose\", \"test\": \"last_match\"}","log_format": "syslog","location": "master->/var/log/syslog","options":{"rules_debug":123}}}'
verbose_mode: False
warning_message: "WARNING: \\(\\d+\\): 'rules_debug' field must be a boolean. The parameter will be ignored"
input: '{"version":1,"origin":{"name":"Integration Test","module":"api"},"command":"log_processing","parameters":{
"event": "{\"it_logtest\" : \"rules_verbose\", \"test\": \"last_match\"}","log_format": "syslog",
"location": "master->/var/log/syslog","options":{"rules_debug":123}}}'
verbose_mode: false
warning_message: ".*WARNING: .*: ('rules_debug' field must be a boolean. The parameter will be ignored).*"
-
name: 'rules_debug_bad_type_object'
rule_file: 'rules_verbose.xml'
name: rules_debug_bad_type_object
rule_file: rules_verbose.xml
rule_id: '880001'
input: '{"version":1,"origin":{"name":"Integration Test","module":"api"},"command":"log_processing","parameters":{"event": "{\"it_logtest\" : \"rules_verbose\", \"test\": \"last_match\"}","log_format": "syslog","location": "master->/var/log/syslog","options":{"rules_debug":{"test":"true"}}}}'
verbose_mode: False
warning_message: "WARNING: \\(\\d+\\): 'rules_debug' field must be a boolean. The parameter will be ignored"
input: '{"version":1,"origin":{"name":"Integration Test","module":"api"},"command":"log_processing","parameters":{
"event": "{\"it_logtest\" : \"rules_verbose\", \"test\": \"last_match\"}","log_format": "syslog",
"location": "master->/var/log/syslog","options":{"rules_debug":{"test":"true"}}}}'
verbose_mode: false
warning_message: ".*WARNING: .*: ('rules_debug' field must be a boolean. The parameter will be ignored).*"
-
name: 'rules_debug_bad_type_array'
rule_file: 'rules_verbose.xml'
name: rules_debug_bad_type_array
rule_file: rules_verbose.xml
rule_id: '880001'
input: '{"version":1,"origin":{"name":"Integration Test","module":"api"},"command":"log_processing","parameters":{"event": "{\"it_logtest\" : \"rules_verbose\", \"test\": \"last_match\"}","log_format": "syslog","location": "master->/var/log/syslog","options":{"rules_debug":["true", "false"]}}}'
verbose_mode: False
warning_message: "WARNING: \\(\\d+\\): 'rules_debug' field must be a boolean. The parameter will be ignored"
input: '{"version":1,"origin":{"name":"Integration Test","module":"api"},"command":"log_processing","parameters":{
"event": "{\"it_logtest\" : \"rules_verbose\", \"test\": \"last_match\"}","log_format": "syslog",
"location": "master->/var/log/syslog","options":{"rules_debug":["true", "false"]}}}'
verbose_mode: false
warning_message: ".*WARNING: .*: ('rules_debug' field must be a boolean. The parameter will be ignored).*"
-
name: 'options_bad_type_boolean'
rule_file: 'rules_verbose.xml'
name: options_bad_type_boolean
rule_file: rules_verbose.xml
rule_id: '880001'
input: '{"version":1,"origin":{"name":"Integration Test","module":"api"},"command":"log_processing","parameters":{"event": "{\"it_logtest\" : \"rules_verbose\", \"test\": \"last_match\"}","log_format": "syslog","location": "master->/var/log/syslog","options":true}}'
verbose_mode: False
warning_message: "WARNING: \\(\\d+\\): 'options' field must be a JSON object. The parameter will be ignored"
input: '{"version":1,"origin":{"name":"Integration Test","module":"api"},"command":"log_processing","parameters":{
"event": "{\"it_logtest\" : \"rules_verbose\", \"test\": \"last_match\"}","log_format": "syslog",
"location": "master->/var/log/syslog","options":true}}'
verbose_mode: false
warning_message: "WARNING: .*: ('options' field must be a JSON object. The parameter will be ignored)"
-
name: 'options_bad_type_array'
rule_file: 'rules_verbose.xml'
name: options_bad_type_array
rule_file: rules_verbose.xml
rule_id: '880001'
input: '{"version":1,"origin":{"name":"Integration Test","module":"api"},"command":"log_processing","parameters":{"event": "{\"it_logtest\" : \"rules_verbose\", \"test\": \"last_match\"}","log_format": "syslog","location": "master->/var/log/syslog","options":["true", "false"]}}'
verbose_mode: False
warning_message: "WARNING: \\(\\d+\\): 'options' field must be a JSON object. The parameter will be ignored"
input: '{"version":1,"origin":{"name":"Integration Test","module":"api"},"command":"log_processing","parameters":{
"event": "{\"it_logtest\" : \"rules_verbose\", \"test\": \"last_match\"}","log_format": "syslog",
"location": "master->/var/log/syslog","options":["true", "false"]}}'
verbose_mode: false
warning_message: "WARNING: .*: ('options' field must be a JSON object. The parameter will be ignored)"
-
name: 'options_bad_type_number'
rule_file: 'rules_verbose.xml'
name: options_bad_type_number
rule_file: rules_verbose.xml
rule_id: '880001'
input: '{"version":1,"origin":{"name":"Integration Test","module":"api"},"command":"log_processing","parameters":{"event": "{\"it_logtest\" : \"rules_verbose\", \"test\": \"last_match\"}","log_format": "syslog","location": "master->/var/log/syslog","options":123456}}'
verbose_mode: False
warning_message: "WARNING: \\(\\d+\\): 'options' field must be a JSON object. The parameter will be ignored"
input: '{"version":1,"origin":{"name":"Integration Test","module":"api"},"command":"log_processing","parameters":{
"event": "{\"it_logtest\" : \"rules_verbose\", \"test\": \"last_match\"}","log_format": "syslog",
"location": "master->/var/log/syslog","options":123456}}'
verbose_mode: false
warning_message: "WARNING: .*: ('options' field must be a JSON object. The parameter will be ignored)"
-
name: 'options_bad_type_string'
rule_file: 'rules_verbose.xml'
name: options_bad_type_string
rule_file: rules_verbose.xml
rule_id: '880001'
input: '{"version":1,"origin":{"name":"Integration Test","module":"api"},"command":"log_processing","parameters":{"event": "{\"it_logtest\" : \"rules_verbose\", \"test\": \"last_match\"}","log_format": "syslog","location": "master->/var/log/syslog","options":"true"}}'
verbose_mode: False
warning_message: "WARNING: \\(\\d+\\): 'options' field must be a JSON object. The parameter will be ignored"
input: '{"version":1,"origin":{"name":"Integration Test","module":"api"},"command":"log_processing","parameters":{
"event": "{\"it_logtest\" : \"rules_verbose\", \"test\": \"last_match\"}","log_format": "syslog",
"location": "master->/var/log/syslog","options":"true"}}'
verbose_mode: false
warning_message: "WARNING: .*: ('options' field must be a JSON object. The parameter will be ignored)"
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import wazuh_testing.tools.agent_simulator as ag
from wazuh_testing.tools.configuration import load_wazuh_configurations
from wazuh_testing.tools.sockets import send_request
from wazuh_testing.tools import REMOTED_SOCKET_PATH


# Marks
Expand Down Expand Up @@ -105,7 +106,7 @@ def test_request(get_configuration, configure_environment, remove_shared_files,
If the agent is disconnected, it raises an error.
As the test has nothing to do with shared configuration files, we removed those rootcheck txt files
from default agent group to reduce the time required by the test to make the checks.
wazuh_min_version: 4.2.0
tier: 0
Expand All @@ -129,20 +130,20 @@ def test_request(get_configuration, configure_environment, remove_shared_files,
- expected_answer:
type: dict_keys
brief: Test cases keys. Used to verify the remoted response.
assertions:
- Verify that the expected answer is in the response.
input_description: A configuration template (test_request_agent_info) is contained in an external YAML file,
(wazuh_request_agent_info.yaml). That template is combined with different test cases defined
in the module. Those include configuration settings for the 'wazuh-remoted' daemon and agents
info.
expected_output:
- Could not find the remoted key loading log
- "expected_answer: {agent.id} {command_request}"
- Remoted unexpected answer
tags:
- simulator
- remoted
Expand All @@ -163,7 +164,7 @@ def test_request(get_configuration, configure_environment, remove_shared_files,

msg_request = f'{agent.id} {command_request}'

response = send_request(msg_request)
response = send_request(msg_request, wazuh_socket=REMOTED_SOCKET_PATH)

assert expected_answer in response, "Remoted unexpected answer"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,14 @@ def test_merged_mg_file_content(metadata, configure_local_internal_options_modul
if os.path.exists(merged_mg_file):
with open(merged_mg_file, 'r') as merged_file:
merged_file_lines = merged_file.readlines()
match_regex = re.compile(rf"^{expected_line}$")
match_regex = re.compile(rf".*{expected_line}.*")
match_expected_line = list(filter(match_regex.match, merged_file_lines))
else:
raise FileNotFoundError(f"The file: {merged_mg_file} was not created.")

expected_conditions = [True, [expected_line + '\n']] if action == 'create' else [False, []]

assert file_exists == expected_conditions[0], f"The file was not {action}d in the multigroups directory.\n"
assert match_expected_line == expected_conditions[1], f"The file is \
{'not' if action == 'created' else ''} in {merged_mg_file}."
if action == 'created':
assert match_expected_line in expected_conditions[1], f"The file is not in {merged_mg_file}."
else:
match_expected_line == expected_conditions[1], f"Unexpected file found in {merged_mg_file}."
52 changes: 31 additions & 21 deletions tests/integration/test_wazuh_db/data/global/wazuhdb_getconfig.yaml
Original file line number Diff line number Diff line change
@@ -1,31 +1,41 @@
---
-
name: 'Get config missing parameter'
name: Get config missing parameter
test_case:
-
input: 'wazuhdb getconfig'
output: "err Invalid DB query syntax, near 'getconfig'"
-
input: '{"version": 1, "origin": {"module": "api"}, "command": "getconfig", "module": "api"}'
output: '{"error":4,"message":"Empty parameters","data":{}}'

-
name: 'Get config empty parameter'
name: Get config empty parameters
test_case:
-
input: 'wazuhdb getconfig '
output: 'err Failed reading wazuh-db config'
-
input: '{"version": 1, "origin": {"module": "api"}, "command": "getconfig", "module": "api", "parameters": {}}'
output: '{"error":5,"message":"Empty section","data":{}}'
-
name: 'Get config wrong parameter'
name: Get config empty section
test_case:
-
input: 'wazuhdb getconfig wrong_parameter'
output: 'err Failed reading wazuh-db config'
-
input: '{"version": 1, "origin": {"module": "api"}, "command": "getconfig", "module": "api", "parameters": {
"section":}}'
output: '{"error":1,"message":"Invalid JSON input","data":{}}'
-
name: 'Get internal config'
name: Get config wrong parameter
test_case:
-
input: 'wazuhdb getconfig internal'
output: "{'wazuh_db': {'commit_time_max': 60, 'commit_time_min': 10, 'open_db_limit': 64, 'worker_pool_size': 8}}"
-
input: '{"version": 1, "origin": {"module": "api"}, "command": "getconfig", "module": "api", "parameters": {
"section": "wrong_parameter"}}'
output: '{"error":6,"message":"Unrecognized or not configured section","data":{}}'
-
name: 'Get wdb config'
name: Get internal config
test_case:
-
input: 'wazuhdb getconfig wdb'
output: "{'wdb': {'backup': [{'database': 'global', 'enabled': True, 'interval': 86400, 'max_files': 3}]}}"
-
input: '{"version": 1, "origin": {"module": "api"}, "command": "getconfig", "module": "api", "parameters": {
"section": "internal"}}'
output: '"data":{"wazuh_db":{"commit_time_max":60,"commit_time_min":10,"open_db_limit":64,"worker_pool_size":8}}'
-
name: Get wdb config
test_case:
-
input: '{"version": 1, "origin": {"module": "api"}, "command": "getconfig", "module": "api", "parameters": {
"section": "wdb"}}'
output: '"data":{"wdb":{"backup":[{"database":"global","enabled":true,"interval":86400,"max_files":3}]}'
4 changes: 2 additions & 2 deletions tests/integration/test_wazuh_db/test_wazuhdb_getconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ def test_sync_agent_groups(configure_sockets_environment, connect_to_sockets_mod
- wazuh_db
- wdb_socket
'''
# Set each case
# Set each case
case_data = test_case[0]
output = case_data["output"]

response = query_wdb(case_data["input"])

# Validate response
assert str(response) == output
assert output in str(response), f"The expected output: {output} was not found in response: {response}"

0 comments on commit bbc1d89

Please sign in to comment.