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

Add tests for invalid config of github and office365 modules #1460

Merged
merged 5 commits into from
Jun 24, 2021
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
73 changes: 73 additions & 0 deletions deps/wazuh_testing/wazuh_testing/github.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Copyright (C) 2015-2021, 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


def callback_detect_enabled_err(line):
if 'wm_github_read(): ERROR: Invalid content for tag \'enabled\' at module \'github\'.' in line:
return line
return None


def callback_detect_only_future_events_err(line):
if 'wm_github_read(): ERROR: Invalid content for tag \'only_future_events\' at module \'github\'.' in line:
return line
return None


def callback_detect_interval_err(line):
if 'wm_github_read(): ERROR: Invalid content for tag \'interval\' at module \'github\'.' in line:
return line
return None


def callback_detect_curl_max_size_err(line):
if 'wm_github_read(): ERROR: Invalid content for tag \'curl_max_size\' at module \'github\'. '\
'The minimum value allowed is 1KB.' in line:
return line
return None


def callback_detect_time_delay_err(line):
if 'wm_github_read(): ERROR: Invalid content for tag \'time_delay\' at module \'github\'.' in line:
return line
return None


def callback_detect_org_name_err(line):
if 'wm_github_read(): ERROR: Empty content for tag \'org_name\' at module \'github\'.' in line:
return line
return None


def callback_detect_api_token_err(line):
if 'wm_github_read(): ERROR: Empty content for tag \'api_token\' at module \'github\'.' in line:
return line
return None


def callback_detect_event_type_err(line):
if 'wm_github_read(): ERROR: Invalid content for tag \'event_type\' at module \'github\'.' in line:
return line
return None


def callback_detect_read_err(line):
if 'wm_github_read(): ERROR: Empty content for tag \'api_auth\' at module \'github\'.' in line:
return line
return None


def callback_detect_start_github(line):
if 'wm_github_main(): INFO: Module GitHub started.' in line:
return line
return None


def detect_github_start(file_monitor):
"""Detect module github starts after restarting Wazuh.

Args:
file_monitor (FileMonitor): File log monitor to detect events
"""
file_monitor.start(timeout=60, callback=callback_detect_start_github)
74 changes: 74 additions & 0 deletions deps/wazuh_testing/wazuh_testing/office365.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Copyright (C) 2015-2021, 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


def callback_detect_enabled_err(line):
if 'wm_office365_read(): ERROR: Invalid content for tag \'enabled\' at module \'office365\'.' in line:
return line
return None


def callback_detect_only_future_events_err(line):
if 'wm_office365_read(): ERROR: Invalid content for tag \'only_future_events\' at module \'office365\'.' in line:
return line
return None


def callback_detect_interval_err(line):
if 'wm_office365_read(): ERROR: Invalid content for tag \'interval\' at module \'office365\'. '\
'The maximum value allowed is 1 day.' in line:
return line
return None


def callback_detect_curl_max_size_err(line):
if 'wm_office365_read(): ERROR: Invalid content for tag \'curl_max_size\' at module \'office365\'. '\
'The minimum value allowed is 1KB.' in line:
return line
return None


def callback_detect_tenant_id_err(line):
if 'wm_office365_read(): ERROR: Empty content for tag \'tenant_id\' at module \'office365\'.' in line:
return line
return None


def callback_detect_client_id_err(line):
if 'wm_office365_read(): ERROR: Empty content for tag \'client_id\' at module \'office365\'.' in line:
return line
return None


def callback_detect_client_secret_err(line):
if 'wm_office365_read(): ERROR: Empty content for tag \'client_secret\' at module \'office365\'.' in line:
return line
return None


def callback_detect_subscription_err(line):
if 'wm_office365_read(): ERROR: Empty content for tag \'subscription\' at module \'office365\'.' in line:
return line
return None


def callback_detect_read_err(line):
if 'wm_office365_read(): ERROR: Empty content for tag \'api_auth\' at module \'office365\'.' in line:
return line
return None


def callback_detect_start_office365(line):
if 'wm_office365_main(): INFO: Module Office365 started.' in line:
return line
return None


def detect_office365_start(file_monitor):
"""Detect module office365 starts after restarting Wazuh.

Args:
file_monitor (FileMonitor): File log monitor to detect events
"""
file_monitor.start(timeout=60, callback=callback_detect_start_office365)
2 changes: 2 additions & 0 deletions docs/tests/integration/test_github/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Overview

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## Code documentation

<!-- ::: tests.integration.test_github.test_configuration.test_invalid -->
2 changes: 2 additions & 0 deletions docs/tests/integration/test_office365/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Overview

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## Code documentation

<!-- ::: tests.integration.test_office365.test_configuration.test_invalid -->
14 changes: 14 additions & 0 deletions tests/integration/test_github/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright (C) 2015-2021, 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

import pytest

from wazuh_testing.github import detect_github_start


@pytest.fixture(scope='module')
def wait_for_github_start(get_configuration, request):
# Wait for module github starts
file_monitor = getattr(request.module, 'wazuh_log_monitor')
detect_github_start(file_monitor)
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
- tags:
- github_integration
apply_to_modules:
- test_invalid
sections:
- section: github
elements:
- enabled:
value: 'ENABLED'
- only_future_events:
value: 'ONLY_FUTURE_EVENTS'
- interval:
value: 'INTERVAL'
- curl_max_size:
value: 'CURL_MAX_SIZE'
- time_delay:
value: 'TIME_DELAY'
- api_auth:
elements:
- org_name:
value: 'ORG_NAME'
- api_token:
value: 'API_TOKEN'
- api_parameters:
elements:
- event_type:
value: 'EVENT_TYPE'
Loading