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

Update API configuration integration tests #2370

Merged
merged 3 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
2 changes: 1 addition & 1 deletion deps/wazuh_testing/wazuh_testing/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def compare_config_api_response(configuration, section):

def get_manager_configuration(section=None, field=None):
"""Get Wazuh manager configuration response from API using GET /manager/configuration

References: https://documentation.wazuh.com/current/user-manual/api/reference.html#operation/api.controllers.manager_controller.get_configuration

Args:
Expand Down
8 changes: 8 additions & 0 deletions tests/integration/test_api/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ def restart_api(get_configuration, request):
# control_service('start', daemon=process_name)
control_service('start')


@pytest.fixture(scope='module')
def wait_for_start(get_configuration, request):
# Wait for API to start
Expand All @@ -105,6 +106,13 @@ def get_api_details():
def restart_api_module(request):
# Stop Wazuh and Wazuh API
control_service('stop')

# Reset api.log and start a new monitor
truncate_file(API_LOG_FILE_PATH)
file_monitor = FileMonitor(API_LOG_FILE_PATH)
setattr(request.module, 'wazuh_log_monitor', file_monitor)

# Start Wazuh API
control_service('start')


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,8 @@
configuration:
https:
enabled: no
key: "/test_cert/server.key"
cert: "/test_cert/server.crt"
use_ca: no
ca: "/test_cert/ca.crt"
- tags:
- https_enabled
configuration:
https:
enabled: yes
key: "/test_cert/server.key"
cert: "/test_cert/server.crt"
use_ca: no
ca: "/test_cert/ca.crt"
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,12 @@

import pytest
import requests
from wazuh_testing.tools import PREFIX
from wazuh_testing.tools.configuration import check_apply_test, get_api_conf

# Marks

pytestmark = pytest.mark.server

# Variables

test_directories = [os.path.join(PREFIX, 'test_cert')]

# Configurations

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
- logs_info
configuration:
logs:
path: /test_logs/test.log
level: info
- tags:
- logs_debug
configuration:
logs:
path: /test_logs/test.log
level: debug
29 changes: 8 additions & 21 deletions tests/integration/test_api/test_config/test_logs/test_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,10 @@
- api
'''
import os
from grp import getgrnam
from pwd import getpwnam

import pytest
from wazuh_testing.api import callback_detect_api_debug
from wazuh_testing.tools import PREFIX
from wazuh_testing.tools import PREFIX, API_LOG_FILE_PATH
from wazuh_testing.tools.configuration import check_apply_test, get_api_conf
from wazuh_testing.tools.monitoring import FileMonitor

Expand All @@ -72,8 +70,7 @@
# Variables

test_directories = [os.path.join(PREFIX, 'test_logs')]
new_log_file = os.path.join(test_directories[0], 'test.log')
file_monitor = FileMonitor(new_log_file)
file_monitor = FileMonitor(API_LOG_FILE_PATH)

# Configurations

Expand All @@ -90,16 +87,6 @@ def get_configuration(request):
return request.param


# Functions

def extra_configuration_before_yield():
# Create the log file with 'wazuh' as owner.
with open(new_log_file, 'w+'):
pass
os.chmod(new_log_file, 0o777)
os.chown(new_log_file, getpwnam("wazuh").pw_uid, getgrnam("wazuh").gr_gid)


# Tests

@pytest.mark.parametrize('tags_to_apply', [
Expand All @@ -108,10 +95,10 @@ def extra_configuration_before_yield():
])
def test_logs(tags_to_apply, get_configuration, configure_api_environment, restart_api):
'''
description: Check if the logs are saved in the desired path and with desired level.
Logs are usually store in '/var/ossec/logs/api.log' and with level 'info'.
In this test the API log has a different path and 'debug' level configured.
It checks if logs are saved in the new path and with 'debug' level.
description: Check if the logs are saved with the desired level.
Logs are always stored in '/var/ossec/logs/api.log', usually with level 'info'.
In this test the API log has 'debug' level configured.
It checks if logs are saved with 'debug' level.

wazuh_min_version: 4.2.0

Expand All @@ -134,7 +121,7 @@ def test_logs(tags_to_apply, get_configuration, configure_api_environment, resta
- Verify that 'DEBUG' messages are written when the value of the 'level' setting is set to 'debug'.

input_description: Different test cases are contained in an external YAML file (conf.yaml)
which includes API configuration parameters (log paths and log levels).
which includes API configuration parameters (log levels).

expected_output:
- r'.*DEBUG: (.*)'
Expand All @@ -144,7 +131,7 @@ def test_logs(tags_to_apply, get_configuration, configure_api_environment, resta
'''
check_apply_test(tags_to_apply, get_configuration['tags'])

# Detect any "DEBUG:" message in the new log path
# Detect any "DEBUG:" message in the log path
if get_configuration['configuration']['logs']['level'] == 'info':
with pytest.raises(TimeoutError):
file_monitor.start(timeout=15, callback=callback_detect_api_debug,
Expand Down