diff --git a/deps/wazuh_testing/wazuh_testing/tools/__init__.py b/deps/wazuh_testing/wazuh_testing/tools/__init__.py index 04f2bb3068..41d8711339 100644 --- a/deps/wazuh_testing/wazuh_testing/tools/__init__.py +++ b/deps/wazuh_testing/wazuh_testing/tools/__init__.py @@ -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') @@ -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': [], @@ -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'} diff --git a/deps/wazuh_testing/wazuh_testing/tools/api_simulator.py b/deps/wazuh_testing/wazuh_testing/tools/api_simulator.py index 539d5a5705..a0633a564c 100644 --- a/deps/wazuh_testing/wazuh_testing/tools/api_simulator.py +++ b/deps/wazuh_testing/wazuh_testing/tools/api_simulator.py @@ -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 diff --git a/deps/wazuh_testing/wazuh_testing/tools/configuration.py b/deps/wazuh_testing/wazuh_testing/tools/configuration.py index 08099091be..214710ff3a 100644 --- a/deps/wazuh_testing/wazuh_testing/tools/configuration.py +++ b/deps/wazuh_testing/wazuh_testing/tools/configuration.py @@ -227,10 +227,12 @@ def purge_multiple_root_elements(str_list: List[str], root_delimeter: str = "" + root_delimeter (str, optional: The expected string to identify when the first root element ends, + by default "" 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: @@ -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\ ): 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. """ @@ -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: @@ -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): @@ -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 \. + 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', @@ -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 \. + 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'] @@ -592,7 +597,7 @@ 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: @@ -600,3 +605,32 @@ def local_internal_options_to_dict(local_internal_options): 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) diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index 750cca0d1e..cee15c37d4 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -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) diff --git a/tests/performance/test_api/conftest.py b/tests/performance/test_api/conftest.py index 2ed7ac1c0e..d1324a68f2 100755 --- a/tests/performance/test_api/conftest.py +++ b/tests/performance/test_api/conftest.py @@ -2,22 +2,24 @@ # Created by Wazuh, Inc. . # 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) @@ -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: diff --git a/tests/performance/test_api/data/configuration.yaml b/tests/performance/test_api/data/configuration.yaml index 7619233e15..48adb3a68f 100755 --- a/tests/performance/test_api/data/configuration.yaml +++ b/tests/performance/test_api/data/configuration.yaml @@ -2,294 +2,3 @@ configuration: host: 'localhost' port: 55000 restart_delay: 30 - -test_cases: - - - endpoint: /cluster/local/info - method: get - parameters: {} - body: {} - - - endpoint: /cluster/nodes - method: get - parameters: {} - body: {} - - - endpoint: /cluster/healthcheck - method: get - parameters: {} - body: {} - - - endpoint: /cluster/status - method: get - parameters: {} - body: {} - - - endpoint: /cluster/local/config - method: get - parameters: {} - body: {} - - - endpoint: /cluster/api/config - method: get - parameters: {} - body: {} - - - endpoint: /cluster/configuration/validation - method: get - parameters: {} - body: {} - - - endpoint: /manager/status - method: get - parameters: {} - body: {} - - - endpoint: /manager/info - method: get - parameters: {} - body: {} - - - endpoint: /manager/configuration - method: get - parameters: {} - body: {} - - - endpoint: /manager/logs - method: get - parameters: {} - body: {} - - - endpoint: /manager/api/config - method: get - parameters: {} - body: {} - - - endpoint: /manager/configuration/validation - method: get - parameters: {} - body: {} - - - endpoint: /mitre - method: get - parameters: {} - body: {} - - - endpoint: /overview/agents - method: get - parameters: {} - body: {} - - - endpoint: /tasks/status - method: get - parameters: {} - body: {} - - - endpoint: /active-response - method: put - parameters: {} - body: - command: custom - custom: True - restart: False - - - endpoint: /rootcheck - method: put - parameters: {} - body: {} - restart: False - - - endpoint: /syscheck - method: put - parameters: {} - body: {} - restart: False - - - endpoint: /rootcheck - method: delete - parameters: {} - body: {} - - - endpoint: /groups - method: post - parameters: {} - body: - group_id: "new_test_group" - - - endpoint: /security/users - method: post - parameters: {} - body: - username: "new_test_user" - password: "Password1!" - - - endpoint: /security/roles - method: post - parameters: {} - body: - name: "new_test_role" - - - endpoint: /security/policies - method: post - parameters: {} - body: - name: "new_test_policy" - policy: - actions: - - "agent:read" - resources: - - "agent:id:99" - effect: "allow" - - - endpoint: /security/rules - method: post - parameters: {} - body: - name: "new_test_security_rule" - rule: - MATCH: - name: "test" - - - endpoint: /agents/group - method: put - parameters: - group_id: "new_test_group" - body: {} - restart: True - - - endpoint: /agents/group/new_test_group/restart - method: put - parameters: {} - body: {} - restart: True - - - endpoint: /agents/restart - method: put - parameters: {} - body: {} - restart: True - - - endpoint: /agents - method: post - parameters: {} - body: - name: "new_test_agent" - ip: "any" - - - endpoint: /agents/insert - method: post - parameters: {} - body: - name: "new_test_agent_insert" - ip: "any" - - - endpoint: /agents/insert/quick - method: post - parameters: - agent_name: "new_test_agent_insert_quick" - body: {} - - - endpoint: /agents - method: get - parameters: {} - body: {} - - - endpoint: /agents/no_group - method: get - parameters: {} - body: {} - - - endpoint: /agents/outdated - method: get - parameters: {} - body: {} - - - endpoint: /decoders - method: get - parameters: {} - body: {} - - - endpoint: /groups - method: get - parameters: {} - body: {} - - - endpoint: /lists - method: get - parameters: {} - body: {} - - - endpoint: /rules - method: get - parameters: {} - body: {} - - - endpoint: /security/users - method: get - parameters: {} - body: {} - - - endpoint: /security/roles - method: get - parameters: {} - body: {} - - - endpoint: /security/policies - method: get - parameters: {} - body: {} - - - endpoint: /security/rules - method: get - parameters: {} - body: {} - - - endpoint: /agents - method: delete - parameters: - agents_list: "all" - status: "all" - older_than: "0s" - body: {} - - - endpoint: /groups - method: delete - parameters: - groups_list: "all" - body: {} - - - endpoint: /security/users - method: delete - parameters: - user_ids: "all" - body: {} - - - endpoint: /security/roles - method: delete - parameters: - role_ids: "all" - body: {} - - - endpoint: /security/policies - method: delete - parameters: - policy_ids: "all" - body: {} - - - endpoint: /security/rules - method: delete - parameters: - rule_ids: "all" - body: {} - - - endpoint: /manager/restart - method: put - parameters: {} - body: {} - restart: True - - - endpoint: /cluster/restart - method: put - parameters: {} - body: {} - restart: True diff --git a/tests/performance/test_api/data/wazuh_api_endpoints_performance.yaml b/tests/performance/test_api/data/wazuh_api_endpoints_performance.yaml new file mode 100755 index 0000000000..f0e458e3a9 --- /dev/null +++ b/tests/performance/test_api/data/wazuh_api_endpoints_performance.yaml @@ -0,0 +1,315 @@ +test_cases: + + - endpoint: /cluster/local/info + method: get + parameters: {} + body: {} + + - endpoint: /cluster/nodes + method: get + parameters: {} + body: {} + + - endpoint: /cluster/healthcheck + method: get + parameters: {} + body: {} + + - endpoint: /cluster/status + method: get + parameters: {} + body: {} + + - endpoint: /cluster/local/config + method: get + parameters: {} + body: {} + + - endpoint: /cluster/api/config + method: get + parameters: {} + body: {} + + - endpoint: /cluster/configuration/validation + method: get + parameters: {} + body: {} + + - endpoint: /manager/status + method: get + parameters: {} + body: {} + + - endpoint: /manager/info + method: get + parameters: {} + body: {} + + - endpoint: /manager/configuration + method: get + parameters: {} + body: {} + + - endpoint: /manager/logs + method: get + parameters: {} + body: {} + + - endpoint: /manager/api/config + method: get + parameters: {} + body: {} + + - endpoint: /manager/configuration/validation + method: get + parameters: {} + body: {} + + - endpoint: /mitre/groups + method: get + parameters: {} + body: {} + + - endpoint: /mitre/metadata + method: get + parameters: {} + body: {} + + - endpoint: /mitre/mitigations + method: get + parameters: {} + body: {} + + - endpoint: /mitre/references + method: get + parameters: {} + body: {} + + - endpoint: /mitre/software + method: get + parameters: {} + body: {} + + - endpoint: /mitre/tactics + method: get + parameters: {} + body: {} + + - endpoint: /mitre/techniques + method: get + parameters: {} + body: {} + + - endpoint: /overview/agents + method: get + parameters: {} + body: {} + + - endpoint: /tasks/status + method: get + parameters: {} + body: {} + + - endpoint: /active-response + method: put + parameters: {} + body: + command: custom + custom: True + restart: False + + - endpoint: /rootcheck + method: put + parameters: {} + body: {} + restart: False + + - endpoint: /syscheck + method: put + parameters: {} + body: {} + restart: False + + - endpoint: /groups + method: post + parameters: {} + body: + group_id: "new_test_group" + + - endpoint: /security/users + method: post + parameters: {} + body: + username: "new_test_user" + password: "Password1!" + + - endpoint: /security/roles + method: post + parameters: {} + body: + name: "new_test_role" + + - endpoint: /security/policies + method: post + parameters: {} + body: + name: "new_test_policy" + policy: + actions: + - "agent:read" + resources: + - "agent:id:99" + effect: "allow" + + - endpoint: /security/rules + method: post + parameters: {} + body: + name: "new_test_security_rule" + rule: + MATCH: + name: "test" + + - endpoint: /agents/group + method: put + parameters: + group_id: "new_test_group" + body: {} + restart: True + + - endpoint: /agents/group/new_test_group/restart + method: put + parameters: {} + body: {} + restart: True + + - endpoint: /agents/restart + method: put + parameters: {} + body: {} + restart: True + + - endpoint: /agents + method: post + parameters: {} + body: + name: "new_test_agent" + ip: "any" + + - endpoint: /agents/insert + method: post + parameters: {} + body: + name: "new_test_agent_insert" + ip: "any" + + - endpoint: /agents/insert/quick + method: post + parameters: + agent_name: "new_test_agent_insert_quick" + body: {} + + - endpoint: /agents + method: get + parameters: {} + body: {} + + - endpoint: /agents/no_group + method: get + parameters: {} + body: {} + + - endpoint: /agents/outdated + method: get + parameters: {} + body: {} + + - endpoint: /decoders + method: get + parameters: {} + body: {} + + - endpoint: /groups + method: get + parameters: {} + body: {} + + - endpoint: /lists + method: get + parameters: {} + body: {} + + - endpoint: /rules + method: get + parameters: {} + body: {} + + - endpoint: /security/users + method: get + parameters: {} + body: {} + + - endpoint: /security/roles + method: get + parameters: {} + body: {} + + - endpoint: /security/policies + method: get + parameters: {} + body: {} + + - endpoint: /security/rules + method: get + parameters: {} + body: {} + + - endpoint: /groups + method: delete + parameters: + groups_list: "all" + body: {} + + - endpoint: /agents + method: delete + parameters: + agents_list: "all" + status: "all" + older_than: "0s" + body: {} + + - endpoint: /security/users + method: delete + parameters: + user_ids: "all" + body: {} + + - endpoint: /security/roles + method: delete + parameters: + role_ids: "all" + body: {} + + - endpoint: /security/policies + method: delete + parameters: + policy_ids: "all" + body: {} + + - endpoint: /security/rules + method: delete + parameters: + rule_ids: "all" + body: {} + + - endpoint: /manager/restart + method: put + parameters: {} + body: {} + restart: True + + - endpoint: /cluster/restart + method: put + parameters: {} + body: {} + restart: True diff --git a/tests/performance/test_api/test_api.py b/tests/performance/test_api/test_api.py deleted file mode 100755 index 1c191fed50..0000000000 --- a/tests/performance/test_api/test_api.py +++ /dev/null @@ -1,47 +0,0 @@ -from json import dumps -from os.path import join, dirname, realpath -from time import sleep - -import pytest -import requests -from yaml import safe_load - -test_data = safe_load(open(join(dirname(realpath(__file__)), 'data', 'configuration.yaml'))) -configuration = test_data['configuration'] -api_details = dict() - -xfailed_items = { - '/active-response': 'Agent simulator not handling active-response messages: ' - 'https://github.com/wazuh/wazuh-qa/issues/1266' -} - - -# Tests -@pytest.mark.parametrize('test_configuration', [configuration]) -@pytest.mark.parametrize('test_case', test_data['test_cases']) -def test_api_endpoints(test_case, test_configuration, set_api_test_environment, api_healthcheck): - """Make an API request for each `test_case`. `test_configuration` fixture is only used to add metadata to the - HTML report.""" - # Apply xfails - test_case['endpoint'] in xfailed_items and pytest.xfail(xfailed_items[test_case['endpoint']]) - - base_url = api_details['base_url'] - headers = api_details['auth_headers'] - response = None - try: - response = getattr(requests, test_case['method'])(f"{base_url}{test_case['endpoint']}", headers=headers, - params=test_case['parameters'], json=test_case['body'], - verify=False) - assert response.status_code == 200 - assert response.json()['error'] == 0 - - finally: - # Add useful information to report as stdout - try: - print(f'Request elapsed time: {response.elapsed.total_seconds():.3f}s\n') - print(f'Status code: {response.status_code}\n') - print(f'Full response: \n{dumps(response.json(), indent=2)}') - except KeyError: - print('No response available') - - test_case['method'] == 'put' and test_case['restart'] and sleep(configuration['restart_delay']) diff --git a/tests/performance/test_api/test_api_endpoints_performance.py b/tests/performance/test_api/test_api_endpoints_performance.py new file mode 100755 index 0000000000..99724e120f --- /dev/null +++ b/tests/performance/test_api/test_api_endpoints_performance.py @@ -0,0 +1,70 @@ +from json import dumps +from os.path import join, dirname, realpath +from time import sleep + +import pytest +import requests +from yaml import safe_load + +restart_delay = safe_load(open(join(dirname(realpath(__file__)), 'data', 'configuration.yaml')) + )['configuration']['restart_delay'] +test_data = safe_load(open(join(dirname(realpath(__file__)), 'data', 'wazuh_api_endpoints_performance.yaml'))) +case_ids = [f"{case['method']}_{case['endpoint']}" for case in test_data['test_cases']] +api_details = dict() + +xfailed_items = { + '/active-response': {'message': 'Agent simulator not handling active-response messages: ' + 'https://github.com/wazuh/wazuh-qa/issues/1266', + 'method': 'put'}, + '/agents/group': {'message': 'Slow agent-group files creation: https://github.com/wazuh/wazuh/issues/8625', + 'method': 'put'}, + '/syscheck': {'message': 'The `queue/alerts/ar` socket does not accept agent lists: ' + 'https://github.com/wazuh/wazuh/issues/9125', + 'method': 'put'}, + '/rootcheck': {'message': 'The `queue/alerts/ar` socket does not accept agent lists: ' + 'https://github.com/wazuh/wazuh/issues/9125', + 'method': 'put'}, + '/agents': {'message': 'The `queue/sockets/auth` socket does not accept agent lists: ' + 'https://github.com/wazuh/wazuh/issues/9127', + 'method': 'delete'}, + '/groups': {'message': 'Timeout caused by agent-group file manipulation in the Framework: ' + 'https://github.com/wazuh/wazuh/issues/9141', + 'method': 'delete'} +} + + +# Tests +@pytest.mark.parametrize('test_case', test_data['test_cases'], ids=case_ids) +def test_api_endpoints(test_case, set_api_test_environment, api_healthcheck): + """Make an API request for each `test_case`. + + Args: + test_case (dict): Dictionary with the endpoint to be tested and the necessary parameters for the test. + set_api_test_environment (fixture): Fixture that modifies the API security options. + api_healthcheck (fixture): Fixture used to check that the API is ready to respond requests. + """ + # Apply xfails + if test_case['endpoint'] in xfailed_items.keys() and \ + test_case['method'] == xfailed_items[test_case['endpoint']]['method']: + pytest.xfail(xfailed_items[test_case['endpoint']]['message']) + + base_url = api_details['base_url'] + headers = api_details['auth_headers'] + response = None + try: + response = getattr(requests, test_case['method'])(f"{base_url}{test_case['endpoint']}", headers=headers, + params=test_case['parameters'], json=test_case['body'], + verify=False) + assert response.status_code == 200 + assert response.json()['error'] == 0 + + finally: + # Add useful information to report as stdout + try: + print(f'Request elapsed time: {response.elapsed.total_seconds():.3f}s\n') + print(f'Status code: {response.status_code}\n') + print(f'Full response: \n{dumps(response.json(), indent=2)}') + except KeyError: + print('No response available') + + test_case['method'] == 'put' and test_case['restart'] and sleep(restart_delay) diff --git a/tests/system/provisioning/agentless_cluster/roles/master-role/tasks/main.yml b/tests/system/provisioning/agentless_cluster/roles/master-role/tasks/main.yml index 5b1e12ba1f..bbb48d5a30 100644 --- a/tests/system/provisioning/agentless_cluster/roles/master-role/tasks/main.yml +++ b/tests/system/provisioning/agentless_cluster/roles/master-role/tasks/main.yml @@ -1,4 +1,8 @@ --- +- name: "Check and update debian repositories" + shell: + cmd: apt-get update --allow-releaseinfo-change + - name: "Installing dependencies using apt" apt: pkg: @@ -12,8 +16,10 @@ - automake - autoconf - libtool - force_apt_get: True + force_apt_get: yes state: present + update_cache: yes + cache_valid_time: 3600 - name: "Clone wazuh repository" git: diff --git a/tests/system/provisioning/agentless_cluster/roles/worker-role/tasks/main.yml b/tests/system/provisioning/agentless_cluster/roles/worker-role/tasks/main.yml index dfea0a1ce5..ea47be9eb5 100644 --- a/tests/system/provisioning/agentless_cluster/roles/worker-role/tasks/main.yml +++ b/tests/system/provisioning/agentless_cluster/roles/worker-role/tasks/main.yml @@ -1,4 +1,8 @@ --- +- name: "Check and update debian repositories" + shell: + cmd: apt-get update --allow-releaseinfo-change + - name: "Installing dependencies using apt" apt: pkg: @@ -13,8 +17,10 @@ - autoconf - libtool - python3-pytest - force_apt_get: True + force_apt_get: yes state: present + update_cache: yes + cache_valid_time: 3600 - name: "Clone wazuh repository" git: diff --git a/tests/system/provisioning/basic_cluster/roles/agent-role/tasks/main.yml b/tests/system/provisioning/basic_cluster/roles/agent-role/tasks/main.yml index b7e3f4b9d6..4ff95f1277 100644 --- a/tests/system/provisioning/basic_cluster/roles/agent-role/tasks/main.yml +++ b/tests/system/provisioning/basic_cluster/roles/agent-role/tasks/main.yml @@ -1,4 +1,8 @@ --- +- name: "Check and update debian repositories" + shell: + cmd: apt-get update --allow-releaseinfo-change + - name: "Installing dependencies using apt" apt: pkg: @@ -13,8 +17,10 @@ - autoconf - libtool - python3-pytest - force_apt_get: True + force_apt_get: yes state: present + update_cache: yes + cache_valid_time: 3600 - name: "Clone wazuh repository" git: diff --git a/tests/system/provisioning/basic_cluster/roles/master-role/tasks/main.yml b/tests/system/provisioning/basic_cluster/roles/master-role/tasks/main.yml index a448cce85d..dbd4f8d578 100644 --- a/tests/system/provisioning/basic_cluster/roles/master-role/tasks/main.yml +++ b/tests/system/provisioning/basic_cluster/roles/master-role/tasks/main.yml @@ -1,4 +1,8 @@ --- +- name: "Check and update debian repositories" + shell: + cmd: apt-get update --allow-releaseinfo-change + - name: "Installing dependencies using apt" apt: pkg: @@ -13,9 +17,9 @@ - autoconf - libtool - sqlite3 - force_apt_get: True + force_apt_get: yes state: present - update-cache: true + update_cache: yes cache_valid_time: 3600 - name: "Clone wazuh repository" diff --git a/tests/system/provisioning/basic_cluster/roles/worker-role/tasks/main.yml b/tests/system/provisioning/basic_cluster/roles/worker-role/tasks/main.yml index 0be482195d..bb2bd19fcd 100644 --- a/tests/system/provisioning/basic_cluster/roles/worker-role/tasks/main.yml +++ b/tests/system/provisioning/basic_cluster/roles/worker-role/tasks/main.yml @@ -1,4 +1,8 @@ --- +- name: "Check and update debian repositories" + shell: + cmd: apt-get update --allow-releaseinfo-change + - name: "Installing dependencies using apt" apt: pkg: @@ -14,9 +18,9 @@ - libtool - python3-pytest - sqlite3 - force_apt_get: True + force_apt_get: yes state: present - update-cache: true + update_cache: yes cache_valid_time: 3600 - name: "Clone wazuh repository" diff --git a/tests/system/provisioning/enrollment_cluster/roles/agent-role/tasks/main.yml b/tests/system/provisioning/enrollment_cluster/roles/agent-role/tasks/main.yml index 64197cf22c..a23f3bcf8d 100644 --- a/tests/system/provisioning/enrollment_cluster/roles/agent-role/tasks/main.yml +++ b/tests/system/provisioning/enrollment_cluster/roles/agent-role/tasks/main.yml @@ -1,4 +1,8 @@ --- +- name: "Check and update debian repositories" + shell: + cmd: apt-get update --allow-releaseinfo-change + - name: "Installing dependencies using apt" apt: pkg: @@ -13,8 +17,10 @@ - autoconf - libtool - python3-pytest - force_apt_get: True + force_apt_get: yes state: present + update_cache: yes + cache_valid_time: 3600 - name: "Clone wazuh repository" git: diff --git a/tests/system/provisioning/enrollment_cluster/roles/master-role/tasks/main.yml b/tests/system/provisioning/enrollment_cluster/roles/master-role/tasks/main.yml index b42a147421..b9afc0d5a3 100644 --- a/tests/system/provisioning/enrollment_cluster/roles/master-role/tasks/main.yml +++ b/tests/system/provisioning/enrollment_cluster/roles/master-role/tasks/main.yml @@ -1,4 +1,8 @@ --- +- name: "Check and update debian repositories" + shell: + cmd: apt-get update --allow-releaseinfo-change + - name: "Installing dependencies using apt" apt: pkg: @@ -12,8 +16,10 @@ - automake - autoconf - libtool - force_apt_get: True + force_apt_get: yes state: present + update_cache: yes + cache_valid_time: 3600 - name: "Clone wazuh repository" git: diff --git a/tests/system/provisioning/enrollment_cluster/roles/worker-role/tasks/main.yml b/tests/system/provisioning/enrollment_cluster/roles/worker-role/tasks/main.yml index 36e0e2e324..c33017f855 100644 --- a/tests/system/provisioning/enrollment_cluster/roles/worker-role/tasks/main.yml +++ b/tests/system/provisioning/enrollment_cluster/roles/worker-role/tasks/main.yml @@ -1,4 +1,8 @@ --- +- name: "Check and update debian repositories" + shell: + cmd: apt-get update --allow-releaseinfo-change + - name: "Installing dependencies using apt" apt: pkg: @@ -13,8 +17,10 @@ - autoconf - libtool - python3-pytest - force_apt_get: True + force_apt_get: yes state: present + update_cache: yes + cache_valid_time: 3600 - name: "Clone wazuh repository" git: