Skip to content

Commit

Permalink
Merge branch 'master' into 1832-filemonitor-handler
Browse files Browse the repository at this point in the history
  • Loading branch information
Rebits committed Sep 7, 2021
2 parents fb39506 + 8e1349e commit 3f4d080
Show file tree
Hide file tree
Showing 17 changed files with 534 additions and 367 deletions.
24 changes: 21 additions & 3 deletions deps/wazuh_testing/wazuh_testing/tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ def get_service():
CLUSTER_SOCKET_PATH = os.path.join(WAZUH_PATH, 'queue', 'cluster')


ANALYSISD_ANALISIS_SOCKET_PATH= os.path.join(QUEUE_SOCKETS_PATH, 'analysis')
ANALYSISD_QUEUE_SOCKET_PATH= os.path.join(QUEUE_SOCKETS_PATH, 'queue')
ANALYSISD_ANALISIS_SOCKET_PATH = os.path.join(QUEUE_SOCKETS_PATH, 'analysis')
ANALYSISD_QUEUE_SOCKET_PATH = os.path.join(QUEUE_SOCKETS_PATH, 'queue')
AUTHD_SOCKET_PATH = os.path.join(QUEUE_SOCKETS_PATH, 'auth')
EXECD_SOCKET_PATH = os.path.join(QUEUE_SOCKETS_PATH, 'com')
LOGCOLLECTOR_SOCKET_PATH = os.path.join(QUEUE_SOCKETS_PATH, 'logcollector')
Expand All @@ -117,7 +117,7 @@ def get_service():
MODULESD_CONTROL_SOCKET_PATH = os.path.join(QUEUE_SOCKETS_PATH, 'control')
MODULESD_KREQUEST_SOCKET_PATH = os.path.join(QUEUE_SOCKETS_PATH, 'krequest')
MODULESD_C_INTERNAL_SOCKET_PATH = os.path.join(CLUSTER_SOCKET_PATH, 'c-internal.sock')
ACTIVE_RESPONSE_SOCKET_PATH = os.path.join(QUEUE_ALERTS_PATH,'ar')
ACTIVE_RESPONSE_SOCKET_PATH = os.path.join(QUEUE_ALERTS_PATH, 'ar')

WAZUH_SOCKETS = {
'wazuh-agentd': [],
Expand Down Expand Up @@ -146,3 +146,21 @@ def get_service():
MODULESD_KREQUEST_SOCKET_PATH,
AUTHD_SOCKET_PATH
]

DISABLE_MONITORD_ROTATE_LOG_OPTION = {'monitord.rotate_log': '0'}
REMOTED_LOCAL_INTERNAL_OPTIONS = {'remoted.debug': '2'}.update(DISABLE_MONITORD_ROTATE_LOG_OPTION)
ANALYSISD_LOCAL_INTERNAL_OPTIONS = {'analysisd.debug': '2'}.update(DISABLE_MONITORD_ROTATE_LOG_OPTION)
AGENTD_LOCAL_INTERNAL_OPTIONS = {'agent.debug': '2', 'execd': '2'}.update(DISABLE_MONITORD_ROTATE_LOG_OPTION)
FIM_LOCAL_INTERNAL_OPTIONS_MANAGER = {'syscheck.debug': '2',
'analysisd.debug': '2'}.update(DISABLE_MONITORD_ROTATE_LOG_OPTION)
FIM_LOCAL_INTERNAL_OPTIONS_AGENT_UNIX = {'syscheck.debug': '2',
'agent.debug': '2'}.update(DISABLE_MONITORD_ROTATE_LOG_OPTION)
FIM_LOCAL_INTERNAL_OPTIONS_AGENT_WINDOWS = {'syscheck.debug': '2',
'windows.debug': '2'}.update(DISABLE_MONITORD_ROTATE_LOG_OPTION)
GCLOUD_LOCAL_INTERNAL_OPTIONS = {'analysisd.debug': '2',
'wazuh_modules.debug': '2'}.update(DISABLE_MONITORD_ROTATE_LOG_OPTION)
LOGTEST_LOCAL_INTERNAL_OPTIONS = {'analysisd.debug': '2'}
REMOTED_LOCAL_INTERNAL_OPTIONS = {'remoted.debug': '2', 'wazuh_database.interval': '2', 'wazuh_db.commit_time': '2',
'wazuh_db.commit_time_max': '3'}.update(DISABLE_MONITORD_ROTATE_LOG_OPTION)
VD_LOCAL_INTERNAL_OPTIONS = {'wazuh_modules.debug': '2'}.update(DISABLE_MONITORD_ROTATE_LOG_OPTION)
WPK_LOCAL_INTERNAL_OPTIONS = {'wazuh_modules.debug': '2'}
2 changes: 1 addition & 1 deletion deps/wazuh_testing/wazuh_testing/tools/api_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def get_logger(self):


class APISimulator:
def __init__(self, host, port, protocol='https', frequency=60, user='wazuh', password='wazuh',
def __init__(self, host, port, protocol='https', frequency=60, user='wazuh-wui', password='wazuh-wui',
external_logger=None, request_percentage=0, request_template=None):
self.host = host
self.port = port
Expand Down
50 changes: 42 additions & 8 deletions deps/wazuh_testing/wazuh_testing/tools/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,12 @@ def purge_multiple_root_elements(str_list: List[str], root_delimeter: str = "</o
Args:
str_list (list or str): The content of the ossec.conf file in a list of str.
root_delimeter (str, optional: The expected string to identify when the first root element ends, by default "</ossec_config>"
root_delimeter (str, optional: The expected string to identify when the first root element ends,
by default "</ossec_config>"
Returns:
list of str : The first N lines of the specified str_list until the root_delimeter is found. The rest of the list will be ignored.
list of str : The first N lines of the specified str_list until the root_delimeter is found. The rest of
the list will be ignored.
"""
line_counter = 0
for line in str_list:
Expand Down Expand Up @@ -277,7 +279,8 @@ def find_module_config(wazuh_conf: ET.ElementTree, section: str, attributes: Lis
Args:
wazuh_conf (ElementTree): An ElementTree object with all the data of the ossec.conf
section (str): Name of the tag or configuration section to search for. For example: vulnerability_detector
attributes (list\<dict\> ): List with section attributes. Needed to check if the section exists with all the searched attributes and values. For example (wodle section) [{'name': 'syscollector'}]
attributes (list of dict): List with section attributes. Needed to check if the section exists with all the
searched attributes and values. For example (wodle section) [{'name': 'syscollector'}]
Returns:
ElementTree: An ElementTree object with the section data found in ossec.conf. None if nothing was found.
"""
Expand Down Expand Up @@ -399,7 +402,8 @@ def load_wazuh_configurations(yaml_file_path: str, test_name: str, params: list
Args:
yaml_file_path (str): Full path of the YAML file to be loaded.
test_name (str): Name of the file which contains the test that will be executed.
params (list, optional) : List of dicts where each dict represents a replacement MATCH -\> REPLACEMENT. Default `None`
params (list, optional) : List of dicts where each dict represents a replacement
MATCH/REPLACEMENT. Default `None`
metadata (list, optional): Custom metadata to be inserted in the configuration. Default `None`
Returns:
Expand Down Expand Up @@ -439,7 +443,8 @@ def set_correct_prefix(configurations, new_prefix):
new_prefix (str): Prefix to be inserted before every path.
Returns:
configurations (list): List of configurations with the correct prefix added in the directories and ignore sections.
configurations (list): List of configurations with the correct prefix added in the directories and
ignore sections.
"""

def inserter(path):
Expand Down Expand Up @@ -512,7 +517,7 @@ def check_apply_test(apply_to_tags: Set, tags: List):
def generate_syscheck_config():
"""Generate all possible syscheck configurations with 'check_*', 'report_changes' and 'tags'.
Every configuration is ready to be applied in the tag \<directories\>.
Every configuration is ready to be applied in the tag directories.
"""
check_platform = 'check_attrs' if sys.platform == 'win32' else 'check_inode'
check_names = ['check_all', 'check_sha1sum', 'check_md5sum', 'check_sha256sum', 'check_size', 'check_owner',
Expand All @@ -529,7 +534,7 @@ def generate_syscheck_config():
def generate_syscheck_registry_config():
"""Generate all possible syscheck configurations with 'check_*', 'report_changes' and 'tags' for Windowsregistries.
Every configuration is ready to be applied in the tag \<directories\>.
Every configuration is ready to be applied in the tag directories.
"""
check_names = ['check_all', 'check_sha1sum', 'check_md5sum', 'check_sha256sum', 'check_size', 'check_owner',
'check_group', 'check_perm', 'check_mtime', 'check_type', 'report_changes']
Expand Down Expand Up @@ -592,11 +597,40 @@ def local_internal_options_to_dict(local_internal_options):
Args:
local_internal_options (List of str): A list containing local internal options.
"""
dict_local_internal_options= {}
dict_local_internal_options = {}
no_comments_options = [line.strip() for line in local_internal_options
if not (line.startswith('#') or line == '\n')]
for line in no_comments_options:
key, value = line.split('=')
dict_local_internal_options[key.rstrip("\n")] = value

return dict_local_internal_options


def get_local_internal_options_dict():
"""Return the local internal options in a dictionary.
Returns:
dict: Local internal options.
"""
local_internal_option_dict = {}
with open(WAZUH_LOCAL_INTERNAL_OPTIONS, 'r') as local_internal_option_file:
configuration_options = local_internal_option_file.readlines()
for configuration_option in configuration_options:
if not configuration_option.startswith('#'):
option_name, option_value = configuration_option.split('=')
local_internal_option_dict[option_name] = option_value

return local_internal_option_dict


def set_local_internal_options_dict(dict_local_internal_options):
"""Set the local internal options using a dictionary.
Args:
local_internal_options_dict (dict): A dictionary containing local internal options.
"""
with open(WAZUH_LOCAL_INTERNAL_OPTIONS, 'w') as local_internal_option_file:
for option_name, option_value in dict_local_internal_options.items():
local_internal_configuration_string = f"{str(option_name)}={str(option_value)}\n"
local_internal_option_file.write(local_internal_configuration_string)
25 changes: 25 additions & 0 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -627,3 +627,28 @@ def file_monitoring(request):

truncate_file(file_to_monitor)
logger.debug(f"Trucanted {file_to_monitor}")


@pytest.fixture(scope='module')
def configure_local_internal_options_module(request):
"""Fixture to configure the local internal options file.
It uses the test variable local_internal_options. This should be
a dictionary wich keys and values corresponds to the internal option configuration, For example:
local_internal_options = {'monitord.rotate_log': '0', 'syscheck.debug': '0' }
"""
try:
local_internal_options = getattr(request.module, 'local_internal_options')
except AttributeError as local_internal_configuration_not_set:
logger.debug('local_internal_options is not set')
raise local_internal_configuration_not_set

backup_local_internal_options = conf.get_local_internal_options_dict()

logger.debug(f"Set local_internal_option to {str(local_internal_options)}")
conf.set_local_internal_options_dict(local_internal_options)

yield

logger.debug(f"Restore local_internal_option to {str(backup_local_internal_options)}")
conf.set_local_internal_options_dict(backup_local_internal_options)
13 changes: 6 additions & 7 deletions tests/performance/test_api/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,24 @@
# Created by Wazuh, Inc. <[email protected]>.
# This program is free software; you can redistribute it and/or modify it under the terms of GPLv2

from os.path import join, dirname, realpath
from time import sleep

import pytest
import requests
from py.xml import html
from yaml import safe_load

from wazuh_testing.api import get_api_details_dict

results = dict()
configuration = safe_load(open(join(dirname(realpath(__file__)), 'data', 'configuration.yaml')))['configuration']


@pytest.fixture(scope='module')
def set_api_test_environment(request):
kwargs = dict()
if hasattr(request.module, 'configuration'):
configuration = getattr(request.module, 'configuration')
kwargs.update({'host': configuration['host'], 'port': configuration['port']})
kwargs.update({'host': configuration['host'], 'port': configuration['port']})

api_details = get_api_details_dict(**kwargs)

Expand Down Expand Up @@ -167,10 +169,7 @@ def pytest_html_results_summary(prefix, summary, postfix):

def pytest_collection_modifyitems(session, config, items):
# Add test configuration as metadata (environment table)
try:
config._metadata = items[0].callspec.params['test_configuration']
except IndexError:
pass
config._metadata = configuration

# Add each test_case metadata as user_properties for its item
for item in items:
Expand Down
Loading

0 comments on commit 3f4d080

Please sign in to comment.