Skip to content

Commit

Permalink
Add changes based in review: write local internal options and other f…
Browse files Browse the repository at this point in the history
…ixes
  • Loading branch information
TomasTurina committed Jun 24, 2021
1 parent 1f100a4 commit af56c2f
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 119 deletions.
2 changes: 0 additions & 2 deletions deps/wazuh_testing/wazuh_testing/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
# 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

import os


def callback_detect_enabled_err(line):
if 'wm_github_read(): ERROR: Invalid content for tag \'enabled\' at module \'github\'.' in line:
Expand Down
2 changes: 0 additions & 2 deletions deps/wazuh_testing/wazuh_testing/office365.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
# 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

import os


def callback_detect_enabled_err(line):
if 'wm_office365_read(): ERROR: Invalid content for tag \'enabled\' at module \'office365\'.' in line:
Expand Down
96 changes: 39 additions & 57 deletions tests/integration/test_github/test_configuration/test_invalid.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
from wazuh_testing import global_parameters
from wazuh_testing.github import callback_detect_enabled_err, callback_detect_only_future_events_err, \
callback_detect_interval_err, callback_detect_curl_max_size_err, callback_detect_time_delay_err, \
callback_detect_org_name_err, callback_detect_api_token_err, callback_detect_event_type_err, \
callback_detect_read_err
callback_detect_org_name_err, callback_detect_api_token_err, callback_detect_event_type_err
from wazuh_testing.tools import LOG_FILE_PATH
from wazuh_testing.tools.configuration import load_wazuh_configurations
from wazuh_testing.tools.monitoring import FileMonitor
Expand All @@ -29,6 +28,10 @@

# configurations

local_internal_options = {
'wazuh_modules.debug': 2
}

cases = [
# Case 1: Invalid enabled (version 4.3)
{
Expand Down Expand Up @@ -165,6 +168,20 @@
configurations = load_wazuh_configurations(configurations_path, __name__, params=params, metadata=metadata)


# callbacks

callbacks = {
'invalid_enabled': callback_detect_enabled_err,
'invalid_only_future_events': callback_detect_only_future_events_err,
'invalid_interval': callback_detect_interval_err,
'invalid_curl_max_size': callback_detect_curl_max_size_err,
'invalid_time_delay': callback_detect_time_delay_err,
'invalid_org_name': callback_detect_org_name_err,
'invalid_api_token': callback_detect_api_token_err,
'invalid_event_type': callback_detect_event_type_err
}


# fixtures

@pytest.fixture(scope='module', params=configurations)
Expand All @@ -173,14 +190,28 @@ def get_configuration(request):
return request.param


@pytest.fixture(scope="module")
def get_local_internal_options():
"""Get internal configuration."""
return local_internal_options


# tests

def test_invalid(get_configuration, configure_environment, reset_ossec_log):
def test_invalid(get_local_internal_options, configure_local_internal_options,
get_configuration, configure_environment, reset_ossec_log):
"""
Checks if an invalid configuration is detected
Using invalid configurations with different attributes,
expect an error message and github unable to start.
Args:
get_local_internal_options (fixture): Get internal configuration.
configure_local_internal_options (fixture): Set internal configuration for testing.
get_configuration (fixture): Get configurations from the module.
configure_environment (fixture): Configure a custom environment for testing.
reset_ossec_log (fixture): Reset ossec.log and start a new monitor
"""
# Configuration error -> ValueError raised
try:
Expand All @@ -191,57 +222,8 @@ def test_invalid(get_configuration, configure_environment, reset_ossec_log):
metadata = get_configuration.get('metadata')
tags_to_apply = metadata['tags']

if tags_to_apply == 'invalid_enabled':
wazuh_log_monitor.start(timeout=global_parameters.default_timeout,
callback=callback_detect_enabled_err,
accum_results=1,
error_message='Did not receive expected '
'Invalid element in the configuration').result()
elif tags_to_apply == 'invalid_only_future_events':
wazuh_log_monitor.start(timeout=global_parameters.default_timeout,
callback=callback_detect_only_future_events_err,
accum_results=1,
error_message='Did not receive expected '
'sched_scan_validate_parameters(): ERROR').result()
elif tags_to_apply == 'invalid_interval':
wazuh_log_monitor.start(timeout=global_parameters.default_timeout,
callback=callback_detect_interval_err,
accum_results=1,
error_message='Did not receive expected '
'sched_scan_validate_parameters(): ERROR').result()
elif tags_to_apply == 'invalid_curl_max_size':
wazuh_log_monitor.start(timeout=global_parameters.default_timeout,
callback=callback_detect_curl_max_size_err,
accum_results=1,
error_message='Did not receive expected '
'sched_scan_validate_parameters(): ERROR').result()
elif tags_to_apply == 'invalid_time_delay':
wazuh_log_monitor.start(timeout=global_parameters.default_timeout,
callback=callback_detect_time_delay_err,
accum_results=1,
error_message='Did not receive expected '
'sched_scan_validate_parameters(): ERROR').result()
elif tags_to_apply == 'invalid_org_name':
wazuh_log_monitor.start(timeout=global_parameters.default_timeout,
callback=callback_detect_org_name_err,
accum_results=1,
error_message='Did not receive expected '
'sched_scan_validate_parameters(): ERROR').result()
elif tags_to_apply == 'invalid_api_token':
wazuh_log_monitor.start(timeout=global_parameters.default_timeout,
callback=callback_detect_api_token_err,
accum_results=1,
error_message='Did not receive expected '
'sched_scan_validate_parameters(): ERROR').result()
elif tags_to_apply == 'invalid_event_type':
wazuh_log_monitor.start(timeout=global_parameters.default_timeout,
callback=callback_detect_event_type_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_read_err,
accum_results=1,
error_message='Did not receive expected '
'wm_gcp_read(): ERROR:').result()
wazuh_log_monitor.start(timeout=global_parameters.default_timeout,
callback=callbacks[tags_to_apply],
accum_results=1,
error_message='Did not receive expected '
'Invalid element in the configuration').result()
98 changes: 40 additions & 58 deletions tests/integration/test_office365/test_configuration/test_invalid.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
from wazuh_testing import global_parameters
from wazuh_testing.office365 import callback_detect_enabled_err, callback_detect_only_future_events_err, \
callback_detect_interval_err, callback_detect_curl_max_size_err, callback_detect_tenant_id_err, \
callback_detect_client_id_err, callback_detect_client_secret_err, callback_detect_subscription_err, \
callback_detect_read_err
callback_detect_client_id_err, callback_detect_client_secret_err, callback_detect_subscription_err
from wazuh_testing.tools import LOG_FILE_PATH
from wazuh_testing.tools.configuration import load_wazuh_configurations
from wazuh_testing.tools.monitoring import FileMonitor
Expand All @@ -29,6 +28,10 @@

# configurations

local_internal_options = {
'wazuh_modules.debug': 2
}

cases = [
# Case 1: Invalid enabled (version 4.3)
{
Expand Down Expand Up @@ -165,6 +168,20 @@
configurations = load_wazuh_configurations(configurations_path, __name__, params=params, metadata=metadata)


# callbacks

callbacks = {
'invalid_enabled': callback_detect_enabled_err,
'invalid_only_future_events': callback_detect_only_future_events_err,
'invalid_interval': callback_detect_interval_err,
'invalid_curl_max_size': callback_detect_curl_max_size_err,
'invalid_tenant_id': callback_detect_tenant_id_err,
'invalid_client_id': callback_detect_client_id_err,
'invalid_client_secret': callback_detect_client_secret_err,
'invalid_subscription': callback_detect_subscription_err
}


# fixtures

@pytest.fixture(scope='module', params=configurations)
Expand All @@ -173,14 +190,28 @@ def get_configuration(request):
return request.param


@pytest.fixture(scope="module")
def get_local_internal_options():
"""Get internal configuration."""
return local_internal_options


# tests

def test_invalid(get_configuration, configure_environment, reset_ossec_log):
def test_invalid(get_local_internal_options, configure_local_internal_options,
get_configuration, configure_environment, reset_ossec_log):
"""
Checks if an invalid configuration is detected
Using invalid configurations with different attributes,
expect an error message and github unable to start.
expect an error message and office365 unable to start.
Args:
get_local_internal_options (fixture): Get internal configuration.
configure_local_internal_options (fixture): Set internal configuration for testing.
get_configuration (fixture): Get configurations from the module.
configure_environment (fixture): Configure a custom environment for testing.
reset_ossec_log (fixture): Reset ossec.log and start a new monitor
"""
# Configuration error -> ValueError raised
try:
Expand All @@ -191,57 +222,8 @@ def test_invalid(get_configuration, configure_environment, reset_ossec_log):
metadata = get_configuration.get('metadata')
tags_to_apply = metadata['tags']

if tags_to_apply == 'invalid_enabled':
wazuh_log_monitor.start(timeout=global_parameters.default_timeout,
callback=callback_detect_enabled_err,
accum_results=1,
error_message='Did not receive expected '
'Invalid element in the configuration').result()
elif tags_to_apply == 'invalid_only_future_events':
wazuh_log_monitor.start(timeout=global_parameters.default_timeout,
callback=callback_detect_only_future_events_err,
accum_results=1,
error_message='Did not receive expected '
'sched_scan_validate_parameters(): ERROR').result()
elif tags_to_apply == 'invalid_interval':
wazuh_log_monitor.start(timeout=global_parameters.default_timeout,
callback=callback_detect_interval_err,
accum_results=1,
error_message='Did not receive expected '
'sched_scan_validate_parameters(): ERROR').result()
elif tags_to_apply == 'invalid_curl_max_size':
wazuh_log_monitor.start(timeout=global_parameters.default_timeout,
callback=callback_detect_curl_max_size_err,
accum_results=1,
error_message='Did not receive expected '
'sched_scan_validate_parameters(): ERROR').result()
elif tags_to_apply == 'invalid_tenant_id':
wazuh_log_monitor.start(timeout=global_parameters.default_timeout,
callback=callback_detect_tenant_id_err,
accum_results=1,
error_message='Did not receive expected '
'sched_scan_validate_parameters(): ERROR').result()
elif tags_to_apply == 'invalid_client_id':
wazuh_log_monitor.start(timeout=global_parameters.default_timeout,
callback=callback_detect_client_id_err,
accum_results=1,
error_message='Did not receive expected '
'sched_scan_validate_parameters(): ERROR').result()
elif tags_to_apply == 'invalid_client_secret':
wazuh_log_monitor.start(timeout=global_parameters.default_timeout,
callback=callback_detect_client_secret_err,
accum_results=1,
error_message='Did not receive expected '
'sched_scan_validate_parameters(): ERROR').result()
elif tags_to_apply == 'invalid_subscription':
wazuh_log_monitor.start(timeout=global_parameters.default_timeout,
callback=callback_detect_subscription_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_read_err,
accum_results=1,
error_message='Did not receive expected '
'wm_gcp_read(): ERROR:').result()
wazuh_log_monitor.start(timeout=global_parameters.default_timeout,
callback=callbacks[tags_to_apply],
accum_results=1,
error_message='Did not receive expected '
'Invalid element in the configuration').result()

0 comments on commit af56c2f

Please sign in to comment.