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

Google Cloud. IT Tests: Fixing and rework for 4.3.0-RC2 #2420

Merged
merged 7 commits into from
Jan 7, 2022
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
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,5 @@ deps/wazuh_testing/wazuh_testing.egg-info/
# SearchUI package-lock
deps/wazuh_testing/wazuh_testing/qa_docs/Search-UI/package-lock.json


# GCP tests configuration file
tests/integration/test_gcloud/data/configuration.yaml
14 changes: 7 additions & 7 deletions deps/wazuh_testing/wazuh_testing/gcloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@ def validate_gcp_event(event):


def callback_detect_start_gcp(line):
if 'wm_gcp_main(): INFO: Module started.' in line:
if 'wm_gcp_pubsub_main(): INFO: Module started.' in line:
return line
return None


def callback_detect_start_fetching_logs(line):
if 'wm_gcp_main(): DEBUG: Starting fetching of logs.' in line:
if 'wm_gcp_pubsub_main(): DEBUG: Starting fetching of logs.' in line:
return line
return None


def callback_detect_start_gcp_sleep(line):
match = re.match(r'.*wm_gcp_main\(\): DEBUG: Sleeping until: (\S+ \S+)', line)
match = re.match(r'.*wm_gcp_pubsub_main\(\): DEBUG: Sleeping until: (\S+ \S+)', line)

if match:
return match.group(1)
Expand All @@ -56,7 +56,7 @@ def detect_gcp_start(file_monitor):


def callback_received_messages_number(line):
match = re.match(r'.*wm_gcp_run\(\): INFO: - INFO - Received and acknowledged (\d+) messages', line)
match = re.match(r'.*wm_gcp_pubsub_run\(\): INFO: - INFO - Received and acknowledged (\d+) messages', line)
if match:
return match.group(1)
return None
Expand Down Expand Up @@ -95,8 +95,8 @@ def callback_detect_schedule_validate_parameters_err(line):


def callback_detect_gcp_read_err(line):
match_err = re.match(r'.*wm_gcp_read\(\): ERROR:.*', line)
match_warn = re.match(r'.*wm_gcp_read\(\): WARNING: File \'\S+\' not found.*', line)
match_err = re.match(r'.*wm_gcp_pubsub_read\(\): ERROR:.*', line)
match_warn = re.match(r'.*wm_gcp_pubsub_read\(\): WARNING: File \'\S+\' not found.*', line)

if match_err:
return line
Expand All @@ -107,7 +107,7 @@ def callback_detect_gcp_read_err(line):

def callback_detect_gcp_wmodule_err(line):
match_err = re.match(r'.*read_main_elements\(\): ERROR: \(\d+\): Invalid element in the configuration.*', line)
match_deb = re.match(r'.*Read_GCP\(\): DEBUG: Empty configuration for module \'gcp-pubsub\'', line)
match_deb = re.match(r'.*Read_GCP_pubsub\(\): DEBUG: Empty configuration for module \'gcp-pubsub\'', line)

if match_err:
return line
Expand Down
35 changes: 24 additions & 11 deletions deps/wazuh_testing/wazuh_testing/qa_docs/schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ predefined_values:
- brute_force_attack
- cache
- cluster
- config
- config
- cors
- cpe
- dos_attack
Expand Down Expand Up @@ -214,49 +216,59 @@ predefined_values:
- fim_multiple_dirs
- fim_nodiff
- fim_prefilter_cmd
- fim_report_changes
- fim_process_priority
- fim_recursion_level
- fim_restrict
- fim_scan
- fim_skip
- fim_stats_integrity_sync
- fim_tags
- fim_timezone_changes
- fim_wildcards_complex
- fim_windows_audit_interval
- fim_registry_ambiguous_confs
- fim_registry_basic_usage
- fim_registry_checks
- fim_registry_ignore
- fim_registry_nodiff
- fim_registry_file_limit
- fim_registry_ignore
- fim_registry_multiple_registries
- fim_registry_nodiff
- fim_registry_recursion_level
- fim_registry_restrict
- fim_report_changes
- fim_restrict
- fim_scan
- fim_skip
- fim_stats_integrity_sync
- fim_synchronization
- fim_tags
- fim_timezone_changes
- fim_wildcards_complex
- fim_windows_audit_interval
- gcloud
- github
- integrity
- interval
- invalid
- keys
- key_polling
- limits
- logcollector
- logging
- logs
- logs
- logtest
- man_in_the_middle
- master
- maximum
- mitre
- msu
- nvd
- office365
- on start
- oval
- pull
- rbac
- realtime
- remote
- remoted
- rids
- rootcheck
- rules
- scan
- schedule
- scheduled
- settings
- simulator
Expand All @@ -268,6 +280,7 @@ predefined_values:
- vulnerability_detector
- wazuh_db
- wdb_socket
- week_day
- who_data
- worker
- wpk
558 changes: 0 additions & 558 deletions mkdocs.yml

This file was deleted.

10 changes: 9 additions & 1 deletion tests/integration/test_gcloud/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from wazuh_testing.tools import WAZUH_PATH
from wazuh_testing.tools.file import write_file, remove_file
from wazuh_testing.gcloud import detect_gcp_start, publish_sync

import wazuh_testing.tools.configuration as conf

@pytest.fixture(scope='session', autouse=True)
def handle_credentials_file():
Expand Down Expand Up @@ -49,3 +49,11 @@ def wait_for_gcp_start(get_configuration, request):
# Wait for module gpc-pubsub starts
file_monitor = getattr(request.module, 'wazuh_log_monitor')
detect_gcp_start(file_monitor)

@pytest.fixture(scope="session", autouse=True)
def configure_internal_options():
local_internal_options = {'wazuh_modules.debug': 2, 'analysisd.debug': 2, 'monitord.rotate_log': 0, 'monitord.day_wait': 0, 'monitord.keep_log_days': 0,'monitord.size_rotate': 0}
conf.set_local_internal_options_dict(local_internal_options)
yield
local_internal_options = {'wazuh_modules.debug': 0, 'analysisd.debug': 0, "monitord.rotate_log": 1, "monitord.day_wait": 10, "monitord.keep_log_days": 31,'monitord.size_rotate': 512}
conf.set_local_internal_options_dict(local_internal_options)
20 changes: 8 additions & 12 deletions tests/integration/test_gcloud/test_configuration/test_invalid.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@
- https://documentation.wazuh.com/current/user-manual/reference/ossec-conf/gcp-pubsub.html

tags:
- gcloud_configuration
- invalid
- config
'''
import os
import sys
Expand All @@ -79,10 +80,11 @@
wazuh_log_monitor = FileMonitor(LOG_FILE_PATH)
test_data_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'data')
configurations_path = os.path.join(test_data_path, 'invalid_conf.yaml')
force_restart_after_restoring = True
force_restart_after_restoring = False

# configurations

daemons_handler_configuration = {'daemons': ['wazuh-modulesd'], 'ignore_errors' : True}
monitoring_modes = ['scheduled']
conf_params = {'PROJECT_ID': global_parameters.gcp_project_id,
'SUBSCRIPTION_NAME': global_parameters.gcp_subscription_name,
Expand All @@ -99,11 +101,10 @@ def get_configuration(request):
"""Get configurations from the module."""
return request.param


# tests

@pytest.mark.skipif(sys.platform == "win32", reason="Windows does not have support for Google Cloud integration.")
def test_invalid(get_configuration, configure_environment, reset_ossec_log):
def test_invalid(get_configuration, configure_environment, reset_ossec_log, daemons_handler):
'''
description: Check if the 'gcp-pubsub' module detects invalid configurations. For this purpose, the test
will configure 'gcp-pubsub' using invalid configuration settings with different attributes.
Expand All @@ -121,6 +122,9 @@ def test_invalid(get_configuration, configure_environment, reset_ossec_log):
- reset_ossec_log:
type: fixture
brief: Reset the 'ossec.log' file and start a new monitor.
- daemons_handler:
type: fixture
brief: Handler of Wazuh daemons.

assertions:
- Verify that the 'gcp-pubsub' module generates error events when invalid configurations are used.
Expand All @@ -138,33 +142,25 @@ def test_invalid(get_configuration, configure_environment, reset_ossec_log):
tags:
- invalid_settings
'''
# Configuration error -> ValueError raised
with pytest.raises(ValueError):
control_service('restart')

tags_to_apply = get_configuration['tags'][0]

if tags_to_apply == 'invalid_gcp_wmodule':
wazuh_log_monitor.start(timeout=global_parameters.default_timeout,
callback=callback_detect_gcp_wmodule_err,
accum_results=1,
error_message='Did not receive expected '
'Invalid element in the configuration').result()
elif tags_to_apply == 'invalid_day_wday':
wazuh_log_monitor.start(timeout=global_parameters.default_timeout,
callback=callback_detect_schedule_validate_parameters_err,
accum_results=1,
error_message='Did not receive expected '
'sched_scan_validate_parameters(): ERROR').result()
elif tags_to_apply == 'invalid_schedule':
wazuh_log_monitor.start(timeout=global_parameters.default_timeout,
callback=callback_detect_schedule_read_err,
accum_results=1,
error_message='Did not receive expected '
'sched_scan_validate_parameters(): ERROR').result()
else:
wazuh_log_monitor.start(timeout=global_parameters.default_timeout,
callback=callback_detect_gcp_read_err,
accum_results=1,
error_message='Did not receive expected '
'wm_gcp_read(): ERROR:').result()
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@
- https://documentation.wazuh.com/current/user-manual/reference/ossec-conf/gcp-pubsub.html

tags:
- gcloud_configuration
- config
- remote
'''
import os
import pytest
Expand Down Expand Up @@ -90,6 +91,7 @@

# configurations

daemons_handler_configuration = {'daemons': ['wazuh-modulesd'], 'ignore_errors' : True}
monitoring_modes = ['scheduled']
conf_params = {'PROJECT_ID': global_parameters.gcp_project_id,
'SUBSCRIPTION_NAME': global_parameters.gcp_subscription_name,
Expand All @@ -100,7 +102,7 @@
p, m = generate_params(extra_params=conf_params,
modes=monitoring_modes)
configurations = load_wazuh_configurations(configurations_path, __name__, params=p, metadata=m)
force_restart_after_restoring = True
force_restart_after_restoring = False


# fixtures
Expand Down Expand Up @@ -147,8 +149,7 @@ def get_remote_configuration(component_name, config):


@pytest.mark.skipif(sys.platform == "win32", reason="Windows does not have support for Google Cloud integration.")
def test_remote_configuration(get_configuration, configure_environment,
restart_wazuh, wait_for_gcp_start):
def test_remote_configuration(get_configuration, configure_environment, reset_ossec_log, daemons_handler, wait_for_gcp_start):
'''
description: Check if the remote configuration matches the local configuration of the 'gcp-pubsub' module.
For this purpose, the test will use different settings and get the remote configuration applied.
Expand Down
61 changes: 21 additions & 40 deletions tests/integration/test_gcloud/test_configuration/test_schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@
- https://documentation.wazuh.com/current/user-manual/reference/ossec-conf/gcp-pubsub.html#interval

tags:
- gcloud_configuration
- config
- schedule
'''
import os
import sys
Expand All @@ -66,6 +67,7 @@
from wazuh_testing.tools import LOG_FILE_PATH
from wazuh_testing.tools.configuration import load_wazuh_configurations
from wazuh_testing.tools.monitoring import FileMonitor
from wazuh_testing.tools.file import truncate_file

# Marks

Expand All @@ -77,10 +79,11 @@
wazuh_log_monitor = FileMonitor(LOG_FILE_PATH)
test_data_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'data')
configurations_path = os.path.join(test_data_path, 'schedule_conf.yaml')
force_restart_after_restoring = True
force_restart_after_restoring = False

# configurations

daemons_handler_configuration = {'daemons': ['wazuh-modulesd']}
monitoring_modes = ['scheduled']
conf_params = {'PROJECT_ID': global_parameters.gcp_project_id,
'SUBSCRIPTION_NAME': global_parameters.gcp_subscription_name,
Expand All @@ -102,7 +105,7 @@ def get_configuration(request):
# tests

@pytest.mark.skipif(sys.platform == "win32", reason="Windows does not have support for Google Cloud integration.")
def test_schedule(get_configuration, configure_environment, restart_wazuh):
def test_schedule(get_configuration, configure_environment, reset_ossec_log, daemons_handler):
'''
description: Check if the 'gcp-pubsub' module is executed in the periods specified in the 'interval' tag.
For this purpose, the test will use different values for the 'interval' tag (a positive number
Expand Down Expand Up @@ -137,44 +140,22 @@ def test_schedule(get_configuration, configure_environment, restart_wazuh):
tags:
- scheduled
'''

str_interval = get_configuration['sections'][0]['elements'][3]['interval']['value']
time_interval = int(''.join(filter(str.isdigit, str_interval)))
tags_to_apply = get_configuration['tags'][0]

if tags_to_apply == 'schedule_day':
if 'M' not in str_interval:
wazuh_log_monitor.start(timeout=global_parameters.default_timeout + time_interval,
callback=callback_detect_schedule_validate_parameters_warn,
accum_results=2,
error_message='Did not receive expected '
'at _sched_scan_validate_parameters(): WARNING:').result()
else:
with pytest.raises(TimeoutError):
event = wazuh_log_monitor.start(timeout=global_parameters.default_timeout,
callback=callback_detect_schedule_validate_parameters_warn).result()
raise AttributeError(f'Unexpected event {event}')

elif tags_to_apply == 'schedule_wday':
if 'w' not in str_interval:
wazuh_log_monitor.start(timeout=global_parameters.default_timeout + time_interval,
callback=callback_detect_schedule_validate_parameters_warn,
accum_results=2,
error_message='Did not receive expected '
'at _sched_scan_validate_parameters(): WARNING:').result()
else:
with pytest.raises(TimeoutError):
event = wazuh_log_monitor.start(timeout=global_parameters.default_timeout,
callback=callback_detect_schedule_validate_parameters_warn).result()
raise AttributeError(f'Unexpected event {event}')

# Warning log must appear in log (cause interval is not compatible with <day/month/week>)
if (tags_to_apply == 'schedule_day' and 'M' not in str_interval) or \
(tags_to_apply == 'schedule_wday' and 'w' not in str_interval) or \
(tags_to_apply == 'schedule_time' and ('d' not in str_interval and 'w' not in str_interval)):
wazuh_log_monitor.start(timeout=global_parameters.default_timeout + time_interval,
callback=callback_detect_schedule_validate_parameters_warn,
error_message='Did not receive expected '
'at _sched_scan_validate_parameters(): WARNING:').result()
# Warning is not suppose to appear
else:
if 'd' not in str_interval and 'w' not in str_interval:
wazuh_log_monitor.start(timeout=global_parameters.default_timeout + time_interval,
callback=callback_detect_schedule_validate_parameters_warn,
accum_results=2,
error_message='Did not receive expected '
'at _sched_scan_validate_parameters(): WARNING:').result()
else:
with pytest.raises(TimeoutError):
event = wazuh_log_monitor.start(timeout=global_parameters.default_timeout,
callback=callback_detect_schedule_validate_parameters_warn).result()
raise AttributeError(f'Unexpected event {event}')
with pytest.raises(TimeoutError):
event = wazuh_log_monitor.start(timeout=global_parameters.default_timeout,
callback=callback_detect_schedule_validate_parameters_warn).result()
raise AttributeError(f'Unexpected event {event}')
Loading