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 4 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.

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 Down
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
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}')
29 changes: 21 additions & 8 deletions tests/integration/test_gcloud/test_functionality/test_day_wday.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@
- https://documentation.wazuh.com/current/user-manual/reference/ossec-conf/gcp-pubsub.html#time

tags:
- gcloud_functionality
- week_day
- scan
- scheduled
- interval
'''
import datetime
import os
Expand Down Expand Up @@ -86,6 +89,7 @@
day = today.day

weekDays = ("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday")
monthDays = {"1": 31, "2": 28, "3": 31, "4": 30, "5": 31, "6": 30, "7": 31, "8": 31, "9": 30, "10": 31, "11": 30, "12": 31}
wday = weekDays[today.weekday()]

now = datetime.datetime.now()
Expand All @@ -94,10 +98,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, 'wazuh_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 Down Expand Up @@ -129,7 +134,7 @@ def get_configuration(request):
])
@pytest.mark.skipif(sys.platform == "win32", reason="Windows does not have support for Google Cloud integration.")
def test_day_wday(tags_to_apply, get_configuration, configure_environment,
restart_wazuh, wait_for_gcp_start):
daemons_handler, wait_for_gcp_start):
'''
description: Check if the 'gcp-pubsub' module starts to pull logs according to the day of the week,
of the month, or time set in the configuration. For this purpose, the test will use
Expand Down Expand Up @@ -202,15 +207,14 @@ def get_next_scan(next_scan_time: str):
error_message='Did not receive expected '
'"Starting fetching of logs" event')


@pytest.mark.parametrize('tags_to_apply', [
({'ossec_day_multiple_conf'}),
({'ossec_wday_multiple_conf'}),
({'ossec_time_multiple_conf'})
])

@pytest.mark.skipif(sys.platform == "win32", reason="Windows does not have support for Google Cloud integration.")
def test_day_wday_multiple(tags_to_apply, get_configuration, configure_environment,
restart_wazuh, wait_for_gcp_start):
def test_day_wday_multiple(tags_to_apply, get_configuration, configure_environment, daemons_handler, wait_for_gcp_start):
'''
description: Check if the 'gcp-pubsub' module calculates the next scan correctly using time intervals
greater than one month, one week, or one day. For this purpose, the test will use different
Expand Down Expand Up @@ -269,14 +273,23 @@ def test_day_wday_multiple(tags_to_apply, get_configuration, configure_environme

next_scan_time = datetime.datetime(int(date[0]), int(date[1]), int(date[2]), int(hour[0]), int(hour[1]),
int(hour[2]))
#raise ValueError(f'HOLA5 {next_scan_time_log}')
#raise ValueError(f'HOLA6 {str_interval}')

if tags_to_apply == {'ossec_day_multiple_conf'}:
if today.month + time_interval <= 12:
assert next_scan_time.month == today.month + time_interval
expected_month = today.month + time_interval
else:
assert next_scan_time.month == (today.month + time_interval) % 12
expected_month = (today.month + time_interval) % 12

if today.day > monthDays[str(expected_month)]:
expected_month = expected_month + 1

assert next_scan_time.month == expected_month

if tags_to_apply == {'ossec_wday_multiple_conf'}:
assert weekDays[next_scan_time.weekday()] == wday
assert next_scan_time.day == (today + datetime.timedelta(weeks=time_interval)).day

if tags_to_apply == {'ossec_time_multiple_conf'}:
assert next_scan_time.day == (today + datetime.timedelta(days=time_interval)).day
Loading